This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
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.
Merge pull request #3 from GSA/feature/tf-actions
Use third-party actions for terraform workflow
- Loading branch information
Showing
7 changed files
with
92 additions
and
70 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,28 @@ | ||
--- | ||
name: apply | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" | ||
AWS_DEFAULT_REGION: us-east-1 | ||
|
||
|
||
jobs: | ||
apply: | ||
name: apply | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: terraform apply | ||
uses: dflook/terraform-apply@v1 | ||
with: | ||
path: . |
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,79 +1,23 @@ | ||
name: Terraform | ||
--- | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
env: | ||
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" | ||
AWS_DEFAULT_REGION: us-east-1 | ||
|
||
|
||
jobs: | ||
terraform: | ||
name: terraform | ||
test: | ||
name: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: setup terraform | ||
uses: hashicorp/setup-terraform@v1 | ||
- name: terraform fmt | ||
uses: dflook/terraform-fmt-check@v1 | ||
with: | ||
terraform_version: ~0.12.0 | ||
|
||
- name: init | ||
run: terraform init | ||
path: . | ||
|
||
- name: fmt | ||
run: terraform fmt -check | ||
|
||
- name: plan | ||
id: plan | ||
run: | | ||
set -o pipefail | ||
tfplan_file=$(mktemp) | ||
echo "::set-output name=tfplan::$tfplan_file" | ||
terraform plan -out=$tfplan_file -no-color | ||
continue-on-error: true # Make sure to post the error to the PR | ||
|
||
- name: publish plan to PR | ||
if: github.event_name == 'pull_request' | ||
uses: actions/github-script@v3 | ||
env: | ||
PLAN: "${{ steps.plan.outputs.stdout }}" | ||
- name: terraform validate | ||
uses: dflook/terraform-validate@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\` | ||
<details><summary>Show Plan</summary> | ||
\`\`\`terraform | ||
${process.env.PLAN} | ||
\`\`\` | ||
</details> | ||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: output | ||
}); | ||
- name: check plan status | ||
if: steps.plan.outcome != 'success' | ||
run: | | ||
echo "Check plan output." | ||
exit 1 | ||
# On push to main, build or change infrastructure according to | ||
# Terraform configuration files | ||
- name: apply | ||
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
run: terraform apply ${{ steps.plan.outputs.tfplan }} | ||
path: . |
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,21 @@ | ||
--- | ||
name: check | ||
|
||
on: | ||
schedule: | ||
- cron: "0 8 * * *" | ||
|
||
jobs: | ||
check_drift: | ||
runs-on: ubuntu-latest | ||
name: Check for drift | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: check | ||
uses: dflook/terraform-check@v1 | ||
with: | ||
path: . | ||
|
||
# TODO open an issue on failure |
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,26 @@ | ||
--- | ||
name: plan | ||
|
||
on: | ||
pull_request: | ||
|
||
env: | ||
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" | ||
AWS_DEFAULT_REGION: us-east-1 | ||
|
||
|
||
jobs: | ||
plan: | ||
name: plan | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: terraform plan | ||
uses: dflook/terraform-plan@v1 | ||
with: | ||
path: . |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
resource "aws_iam_user" "default" { | ||
name = var.name | ||
name = var.name | ||
|
||
# Ensure we can delete the user if non-terraform MFA or login profiles are | ||
# created. | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_iam_user_group_membership" "default" { | ||
user = aws_iam_user.default.name | ||
user = aws_iam_user.default.name | ||
groups = var.groups | ||
} |
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