File tree Expand file tree Collapse file tree 3 files changed +48
-5
lines changed
07-managing-multiple-environments/file-structure Expand file tree Collapse file tree 3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change 44 push :
55 branches :
66 - main
7+ tags :
8+ - v\d+\.\d+\.\d+$
79 pull_request :
810
911jobs :
3638 - name : Terraform Plan
3739 id : plan
3840 if : github.event_name == 'pull_request'
39- run : terraform plan -no-color
41+ run : terraform plan -var db_pass=${{secrets.DB_PASS }} - no-color
4042 continue-on-error : true
4143
42447072 if : steps.plan.outcome == 'failure'
7173 run : exit 1
7274
73- # - name: Terraform Apply
74- # if: github.ref == 'refs/heads/main' && github.event_name == 'push'
75- # run: terraform apply -auto-approve
75+ - name : Check tag
76+ id : check-tag
77+ run : |
78+ if [[ ${{ github.ref }} =~ ^refs/tags/vd+\.d+\.d+$ ]]; then echo ::set-output name=environment::production
79+ elif [[ github.ref == 'refs/heads/main' ]]; then echo ::set-output name=environment::staging
80+ else echo ::set-output name=environment::unknown
81+ fi
82+
83+ - name : Terraform Apply Staging
84+ if : steps.check-tag.outputs.environment == 'production' && github.event_name == 'push'
85+ working-directory : 07-managing-multiple-environments/file-structure/staging
86+ run : terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve
87+
88+ - name : Terraform Apply Production
89+ if : steps.check-tag.outputs.environment == 'staging' && github.event_name == 'push'
90+ working-directory : 07-managing-multiple-environments/file-structure/production
91+ run : terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve
Original file line number Diff line number Diff line change 1+ terraform {
2+ # Assumes s3 bucket and dynamo DB table already set up
3+ # See /code/03-basics/aws-backend
4+ backend "s3" {
5+ bucket = " devops-directive-tf-state"
6+ key = " 07-managing-multiple-environments/global/terraform.tfstate"
7+ region = " us-east-1"
8+ dynamodb_table = " terraform-state-locking"
9+ encrypt = true
10+ }
11+
12+ required_providers {
13+ aws = {
14+ source = " hashicorp/aws"
15+ version = " ~> 3.0"
16+ }
17+ }
18+ }
19+
20+ provider "aws" {
21+ region = " us-east-1"
22+ }
23+
24+ # Route53 zone is shared across staging and production
25+ resource "aws_route53_zone" "primary" {
26+ name = " mysuperawesomesite.com"
27+ }
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ module "web_app" {
3939 domain = " mysuperawesomesite.com"
4040 environment_name = local. environment_name
4141 instance_type = " t2.small"
42- create_dns_zone = true
42+ create_dns_zone = false
4343 db_name = " ${ local . environment_name } mydb"
4444 db_user = " foo"
4545 db_pass = var. db_pass
You can’t perform that action at this time.
0 commit comments