mirror of
https://github.com/sidpalas/devops-directive-terraform-course.git
synced 2025-12-13 14:21:14 +00:00
Compare commits
13 Commits
test-pr-fl
...
feature/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f21960b178 | ||
|
|
7ac8179ed7 | ||
|
|
99fa5aa790 | ||
|
|
b9126d2648 | ||
|
|
9904d34734 | ||
|
|
158d863b3a | ||
|
|
3d18f52dfa | ||
|
|
d040956dae | ||
|
|
314a68cc9b | ||
|
|
563bef8b73 | ||
|
|
00bde26962 | ||
|
|
934164b7ec | ||
|
|
2e3891b7dc |
32
.github/workflows/terraform.yml
vendored
32
.github/workflows/terraform.yml
vendored
@@ -4,6 +4,8 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- v[0-9]+\.[0-9]+\.[0-9]+$
|
||||
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/github-script@0.9.0
|
||||
@@ -70,6 +72,28 @@ 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\/v[0-9]+\.[0-9]+\.[0-9]+$" ]]; 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 Global
|
||||
if: github.event_name == 'push'
|
||||
working-directory: 07-managing-multiple-environments/file-structure/global
|
||||
run: |
|
||||
terraform init
|
||||
terraform apply -auto-approve
|
||||
|
||||
- name: Terraform Apply Staging
|
||||
if: steps.check-tag.outputs.environment == 'staging' && github.event_name == 'push'
|
||||
run: terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve
|
||||
|
||||
- name: Terraform Apply Production
|
||||
if: steps.check-tag.outputs.environment == 'production' && github.event_name == 'push'
|
||||
working-directory: 07-managing-multiple-environments/file-structure/production
|
||||
run: |
|
||||
terraform init
|
||||
terraform apply -var db_pass=${{secrets.DB_PASS }} -auto-approve
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -39,7 +39,7 @@ module "web_app" {
|
||||
domain = "mysuperawesomesite.com"
|
||||
environment_name = local.environment_name
|
||||
instance_type = "t2.small"
|
||||
create_dns_zone = true
|
||||
create_dns_zone = false
|
||||
db_name = "${local.environment_name}mydb"
|
||||
db_user = "foo"
|
||||
db_pass = var.db_pass
|
||||
|
||||
Reference in New Issue
Block a user