Skip to content

Commit 11373c6

Browse files
committed
initial commit
0 parents  commit 11373c6

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

.github/workflows/terraform.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Terraform Deployment
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
9+
jobs:
10+
terraform:
11+
runs-on: ubuntu-latest
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Setup Terraform
22+
uses: hashicorp/setup-terraform@v2
23+
with:
24+
terraform_version: 1.8.3
25+
26+
- name: Terraform Init
27+
run: |
28+
cd infra && terraform init \
29+
-backend-config="bucket=${{ env.TERRAFORM_S3_STATEFILE_BUCKET }}" \
30+
-backend-config="${{ github.event.repository.name }}" \
31+
-backend-config="region=${{ env.AWS_REGION }}" \
32+
-backend-config="dynamodb_table=${{ env.TERRAFORM_DYNAMODB_LOCK_TABLE }}"
33+
34+
- name: Terraform Validate
35+
run: terraform validate
36+
37+
- name: Terraform Create/Select Dev Workspace
38+
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
39+
id: select-dev-workspace
40+
run: |
41+
terraform workspace list | grep -q "dev" || terraform workspace new dev
42+
terraform workspace select dev
43+
44+
- name: Terraform Plan for Dev
45+
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
46+
id: terraform-plan-dev
47+
run: terraform plan -var-file="envs/dev/terraform.tfvars" -out=dev.plan
48+
49+
- name: Terraform Apply for Dev
50+
id: terraform-apply-dev
51+
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
52+
run: terraform apply dev.plan --auto-approve
53+
54+
- name: Terraform Create/Select Prod Workspace
55+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
56+
id: select-prod-workspace
57+
run: |
58+
terraform workspace list | grep -q "prod" || terraform workspace new prod
59+
terraform workspace select prod
60+
61+
- name: Terraform Plan for Prod
62+
id: terraform-plan-prod
63+
run: terraform plan -var-file="envs/prod/terraform.tfvars" -out=prod.plan
64+
65+
- name: Terraform Apply for Prod
66+
id: terraform-apply-prod
67+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
68+
run: terraform apply prod.plan --auto-approve

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.terraform

infra/envs/dev/terraform.tfvars

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bucket_name="DEV-buildrun-pipeline-123-bucket"

infra/envs/prod/terraform.tfvars

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bucket_name="PROD-buildrun-pipeline-123-bucket"

infra/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "aws_s3_bucket" "myBucket" {
2+
bucket = var.bucket_name
3+
}

infra/providers.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "sa-east-1"
3+
}

infra/variables.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "bucket_name" {
2+
nullable = false
3+
}

readme.md

Whitespace-only changes.

0 commit comments

Comments
 (0)