Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAST: fixes to GitHub workflow and 02/net outputs #976

Merged
merged 5 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions fast/assets/templates/workflow-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,22 @@ jobs:
name: Terraform plan
continue-on-error: true
run: |
echo -e "## Plan Output\n\n\`\`\`hcl" >> $$GITHUB_STEP_SUMMARY
terraform plan -input=false -out ../plan.out -no-color |tee -a $$GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $$GITHUB_STEP_SUMMARY
terraform plan -input=false -out ../plan.out -no-color

- id: tf-apply
if: github.event.pull_request.merged == true
if: github.event.pull_request.merged == true && success()
name: Terraform apply
continue-on-error: true
run: |
echo -e "## Apply Output\n\n\`\`\`hcl" >> $$GITHUB_STEP_SUMMARY
terraform apply -input=false -auto-approve -no-color ../plan.out |tee -a $$GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $$GITHUB_STEP_SUMMARY
terraform apply -input=false -auto-approve -no-color ../plan.out

- id: pr-comment
name: Post comment to Pull Request
continue-on-error: true
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: terraform\n$${{ steps.tf-plan.outputs.stdout }}
PLAN: $${{ steps.tf-plan.outputs.stdout }}\n$${{ steps.tf-plan.outputs.stderr }}
with:
script: |
const output = `### Terraform Initialization \`$${{ steps.tf-init.outcome }}\`
Expand Down Expand Up @@ -153,4 +150,37 @@ jobs:
body: output
})

# jq -j -r '.resource_changes[] | (.change.actions | join(",")), " ", .address, "\n" ' foo.json
- id: pr-short-comment
name: Post comment to Pull Request
uses: actions/github-script@v6
if: github.event_name == 'pull_request' && steps.pr-comment.outcome != 'success'
with:
script: |
const output = `### Terraform Initialization \`$${{ steps.tf-init.outcome }}\`

### Terraform Validation \`$${{ steps.tf-validate.outcome }}\`

### Terraform Plan \`$${{ steps.tf-plan.outcome }}\`

Plan output is in the action log.

### Terraform Apply \`$${{ steps.tf-apply.outcome }}\`

*Pusher: @$${{ github.actor }}, Action: \`$${{ github.event_name }}\`, Working Directory: \`$${{ env.tf_actions_working_dir }}\`, Workflow: \`$${{ github.workflow }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

- id: check-plan
name: Check plan failure
if: steps.tf-plan.outcome != 'success'
run: exit 1

- id: check-apply
name: Check apply failure
if: github.event.pull_request.merged == true && steps.tf-apply.outcome != 'success'
run: exit 1
2 changes: 1 addition & 1 deletion fast/stages/02-networking-nva/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ locals {
resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
filename = "${try(pathexpand(var.outputs_location), "")}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode(local.tfvars)
}

Expand Down
2 changes: 1 addition & 1 deletion fast/stages/02-networking-peering/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ locals {
resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
filename = "${try(pathexpand(var.outputs_location), "")}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode(local.tfvars)
}

Expand Down
2 changes: 1 addition & 1 deletion fast/stages/02-networking-separate-envs/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ locals {
resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
filename = "${try(pathexpand(var.outputs_location), "")}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode(local.tfvars)
}

Expand Down
2 changes: 1 addition & 1 deletion fast/stages/02-networking-vpn/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ locals {
resource "local_file" "tfvars" {
for_each = var.outputs_location == null ? {} : { 1 = 1 }
file_permission = "0644"
filename = "${pathexpand(var.outputs_location)}/tfvars/02-networking.auto.tfvars.json"
filename = "${try(pathexpand(var.outputs_location), "")}/tfvars/02-networking.auto.tfvars.json"
content = jsonencode(local.tfvars)
}

Expand Down