-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add GitHub workflow to build and upload * Simplify terraform deployments * Remove terraform workspaces * Combine tf_backend and init stacks and deploy tf backend to the same AWS account * Add terraform jobs to GitHub actions workflow * Set bot webhook in GitHub workflow
- Loading branch information
Showing
12 changed files
with
167 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Build, Upload and Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-upload-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build | ||
run: | | ||
cd bot | ||
GOARCH=amd64 GOOS=linux go build -o bootstrap main.go | ||
- name: Zip | ||
run: | | ||
cd bot | ||
zip lambda_function.zip bootstrap | ||
- name: Configure AWS credentials to upload bundle | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: ${{ vars.AWS_REGION }} | ||
role-to-assume: ${{ vars.PIPELINE_EXEC_ROLE_ARN }} | ||
role-session-name: GitHubActions | ||
role-duration-seconds: 3600 | ||
|
||
- name: Upload to S3 | ||
run: aws s3 cp bot/lambda_function.zip s3://${{ vars.S3_LAMBDA_BUCKET }}/lambda_function.zip | ||
|
||
- name: Set up Terraform | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_wrapper: false | ||
|
||
- name: Terraform init | ||
run: | | ||
cd infra | ||
terraform init \ | ||
-backend-config="region=${{ vars.AWS_REGION }}" \ | ||
-backend-config="bucket=${{ vars.TERRAFORM_STATE_BUCKET }}" | ||
- name: Terraform apply | ||
run: | | ||
cd infra | ||
terraform apply -auto-approve -var aws_region=${{ vars.AWS_REGION }} -var lambda_bucket=${{ vars.S3_LAMBDA_BUCKET }} -var bot_token=${{ secrets.BOT_TOKEN }} | ||
- name: Set webhook URL | ||
shell: bash | ||
run: | | ||
cd infra | ||
WEBHOOK_URL=$(terraform output -raw webhook_url) | ||
curl https://api.telegram.org/bot${{ secrets.BOT_TOKEN }}/setWebhook -F "url=$WEBHOOK_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
locals { | ||
workspace_prefixes = { | ||
default = "dev" | ||
development = "dev" | ||
production = "prod" | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.init_aws_region | ||
profile = var.init_aws_profile[terraform.workspace] | ||
region = var.init_aws_region | ||
} | ||
|
||
# S3 bucket to store lambda function codes | ||
resource "aws_s3_bucket" "lambda_bucket" { | ||
bucket = "${local.workspace_prefixes[terraform.workspace]}.${var.init_lambda_bucket}" | ||
bucket = var.init_lambda_bucket | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
resource "aws_s3_bucket" "terraform_state" { | ||
bucket = var.terraform_state_bucket | ||
} | ||
|
||
resource "aws_dynamodb_table" "terraform_lock" { | ||
name = var.terraform_state_lock_dynamodb_table | ||
billing_mode = "PAY_PER_REQUEST" | ||
hash_key = "LockID" | ||
|
||
attribute { | ||
name = "LockID" | ||
type = "S" | ||
} | ||
|
||
tags = { | ||
Name = "TerraformStateLocking" | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "terraform_backend_access_policy" { | ||
name = "TerraformBackendAccessPolicy" | ||
path = "/" | ||
description = "Policy for allowing access to terraform backend S3 bucket and DynamoDB state lock table" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": "s3:ListBucket", | ||
"Resource": "${aws_s3_bucket.terraform_state.arn}" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["s3:GetObject", "s3:PutObject"], | ||
"Resource": "${aws_s3_bucket.terraform_state.arn}/*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"dynamodb:DescribeTable", | ||
"dynamodb:GetItem", | ||
"dynamodb:PutItem", | ||
"dynamodb:DeleteItem" | ||
], | ||
"Resource": "${aws_dynamodb_table.terraform_lock.arn}" | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.