-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add github action workflow (#1)
- Loading branch information
Showing
3 changed files
with
48 additions
and
5 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 |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
push: | ||
branches: | ||
- main | ||
tags: | ||
- v\d+\.\d+\.\d+$ | ||
pull_request: | ||
|
||
jobs: | ||
|
@@ -36,7 +38,7 @@ jobs: | |
- name: Terraform Plan | ||
id: plan | ||
if: github.event_name == 'pull_request' | ||
run: terraform plan -no-color | ||
run: terraform plan -var db_pass=${{secrets.DB_PASS }} -no-color | ||
continue-on-error: true | ||
|
||
- uses: actions/[email protected] | ||
|
@@ -70,6 +72,20 @@ jobs: | |
if: steps.plan.outcome == 'failure' | ||
run: exit 1 | ||
|
||
# - name: Terraform Apply | ||
# if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
# run: terraform apply -auto-approve | ||
- name: Check tag | ||
id: check-tag | ||
run: | | ||
if [[ ${{ github.ref }} =~ ^refs/tags/vd+\.d+\.d+$ ]]; then echo ::set-output name=environment::production | ||
elif [[ github.ref == 'refs/heads/main' ]]; then echo ::set-output name=environment::staging | ||
else echo ::set-output name=environment::unknown | ||
fi | ||
- name: Terraform Apply Staging | ||
if: steps.check-tag.outputs.environment == 'production' && github.event_name == 'push' | ||
working-directory: 07-managing-multiple-environments/file-structure/staging | ||
run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve | ||
|
||
- name: Terraform Apply Production | ||
if: steps.check-tag.outputs.environment == 'staging' && github.event_name == 'push' | ||
working-directory: 07-managing-multiple-environments/file-structure/production | ||
run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve |
27 changes: 27 additions & 0 deletions
27
07-managing-multiple-environments/file-structure/global/main.tf
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,27 @@ | ||
terraform { | ||
# Assumes s3 bucket and dynamo DB table already set up | ||
# See /code/03-basics/aws-backend | ||
backend "s3" { | ||
bucket = "devops-directive-tf-state" | ||
key = "07-managing-multiple-environments/global/terraform.tfstate" | ||
region = "us-east-1" | ||
dynamodb_table = "terraform-state-locking" | ||
encrypt = true | ||
} | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.0" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
# Route53 zone is shared across staging and production | ||
resource "aws_route53_zone" "primary" { | ||
name = "mysuperawesomesite.com" | ||
} |
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