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

Added input.plan-id and output.has-changes #19

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
03db546
update
zdmytriv Aug 8, 2023
8dba22d
update
zdmytriv Aug 9, 2023
bfc926c
update
zdmytriv Aug 9, 2023
51028a5
update
zdmytriv Aug 9, 2023
0760bdb
update
zdmytriv Aug 9, 2023
c4ca3d2
update
zdmytriv Aug 9, 2023
758d7f6
update
zdmytriv Aug 9, 2023
f25a909
update
zdmytriv Aug 9, 2023
e029db4
update
zdmytriv Aug 9, 2023
2d19d9d
update
zdmytriv Aug 9, 2023
e311916
update
zdmytriv Aug 9, 2023
3a788d7
update
zdmytriv Aug 9, 2023
bc60da7
update
zdmytriv Aug 9, 2023
2fdb804
update
zdmytriv Aug 9, 2023
982a4e2
update
zdmytriv Aug 9, 2023
5dd0740
update
zdmytriv Aug 9, 2023
6c4749d
update
zdmytriv Aug 9, 2023
7dd84ad
update
zdmytriv Aug 9, 2023
3a67818
update
zdmytriv Aug 9, 2023
0cc1fb7
update
zdmytriv Aug 9, 2023
8f5df1d
update
zdmytriv Aug 9, 2023
b914725
update
zdmytriv Aug 9, 2023
9f58bc1
update
zdmytriv Aug 9, 2023
217a6d9
update
zdmytriv Aug 9, 2023
45ad1fc
update
zdmytriv Aug 9, 2023
c0afc5a
update
zdmytriv Aug 9, 2023
2691228
update
zdmytriv Aug 9, 2023
0a61e63
update
zdmytriv Aug 9, 2023
a8241eb
update
zdmytriv Aug 10, 2023
84edc5d
update
zdmytriv Aug 10, 2023
b2726f9
update
zdmytriv Aug 10, 2023
e4661d4
update
zdmytriv Aug 10, 2023
0fbb4ec
update
zdmytriv Aug 10, 2023
1082e8c
update
zdmytriv Aug 10, 2023
6d10f5e
update
zdmytriv Aug 10, 2023
bae76f2
update
zdmytriv Aug 10, 2023
ebfc00d
update
zdmytriv Aug 10, 2023
f891bdf
update
zdmytriv Aug 10, 2023
e2fbe5e
update
zdmytriv Aug 10, 2023
0db0946
update
zdmytriv Aug 10, 2023
6f8650c
update
zdmytriv Aug 10, 2023
4e0af4f
update
zdmytriv Aug 10, 2023
5592aca
update
zdmytriv Aug 10, 2023
e7810d7
update
zdmytriv Aug 10, 2023
ea77bf4
update
zdmytriv Aug 10, 2023
bb66c42
update
zdmytriv Aug 10, 2023
e8889f3
update
zdmytriv Aug 10, 2023
98a9e7f
update
zdmytriv Aug 10, 2023
abbc8fa
update
zdmytriv Aug 10, 2023
11f7328
update
zdmytriv Aug 10, 2023
7962317
update
zdmytriv Aug 10, 2023
6df5e0e
update
zdmytriv Aug 10, 2023
680be66
update
zdmytriv Aug 10, 2023
75b0d2d
update
zdmytriv Aug 10, 2023
3726c04
update
zdmytriv Aug 10, 2023
c77122c
update
zdmytriv Aug 11, 2023
074208f
update
zdmytriv Aug 11, 2023
5d9363f
update
zdmytriv Aug 11, 2023
c644144
update
zdmytriv Aug 11, 2023
b686a10
update
zdmytriv Aug 14, 2023
940538a
update
zdmytriv Aug 15, 2023
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ this action. For more on setting up those components, see the `gitops` component
| debug | Enable action debug mode. Default: 'false' | false | false |
| enable-infracost | Whether to enable infracost summary. Requires secret `infracost-api-key` to be specified. Default: 'false | false | false |
| infracost-api-key | Infracost API key | N/A | false |
| plan-id | Suffix that will be used for plan file name to uniquely identify it. Default: github.sha | ${{ github.sha }} | true |
| stack | The stack name for the given component. | N/A | true |
| terraform-plan-role | The AWS role to be used to plan Terraform. | N/A | true |
| terraform-state-bucket | The S3 Bucket where the planfiles are stored. | N/A | true |
Expand All @@ -146,6 +147,11 @@ this action. For more on setting up those components, see the `gitops` component
| token | Used to pull node distributions for Atmos from Cloud Posse's GitHub repository. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ${{ github.server\_url == 'https://github.com' && github.token \|\| '' }} | false |


## Outputs

| Name | Description |
|------|-------------|
| has-changes | Has Changes |
<!-- markdownlint-restore -->


Expand Down
56 changes: 42 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
component-path:
description: "The path to the base component. Atmos defines this value as component_path."
required: true
plan-id:
description: "Suffix that will be used for plan file name to uniquely identify it. Default: github.sha"
required: true
default: "${{ github.sha }}"
terraform-plan-role:
description: "The AWS role to be used to plan Terraform."
required: true
Expand Down Expand Up @@ -55,6 +59,16 @@ inputs:
not supplied by the user. When running this action on github.com, the default value is sufficient. When running on
GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
outputs:
plan-file-path:
description: Plan File
value: ${{ steps.atmos-plan.outputs.plan_file_path }}
plan-file:
description: Plan File
value: ${{ steps.atmos-plan.outputs.plan_file }}
has-changes:
description: Has Changes
value: ${{ steps.atmos-plan.outputs.has_changes }}

runs:
using: "composite"
Expand Down Expand Up @@ -83,7 +97,7 @@ runs:
stack: ${{ inputs.stack }}
settings-path: github.actions_enabled

- name: Check if Action is Enable
- name: Check if Action is Enabled
id: settings
shell: bash
run: |
Expand Down Expand Up @@ -120,17 +134,29 @@ runs:
id: atmos-plan
shell: bash
run: |
PLAN_FILE=$(echo "${{ inputs.stack }}-${{ inputs.component }}-${{github.sha}}.planfile" | sed 's#/#_#g')
PLAN_FILE=$(echo "${{ inputs.stack }}-${{ inputs.component }}-${{ inputs.plan-id }}.planfile" | sed 's#/#_#g')
PLAN_FILE_PATH=$(pwd)
ATMOS_BASE_PATH=$GITHUB_WORKSPACE atmos terraform plan ${{ inputs.component }} \

TERRAFORM_OUTPUT=$(ATMOS_BASE_PATH=$GITHUB_WORKSPACE atmos terraform plan ${{ inputs.component }} \
--stack ${{ inputs.stack }} \
-out=$PLAN_FILE_PATH/$PLAN_FILE \
-input=false
-lock=false \
-input=false \
-no-color)

if echo "$TERRAFORM_OUTPUT" | grep -q '^No changes. Your infrastructure matches the configuration.'; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Found changes"
fi

echo "plan_file=$PLAN_FILE" >> $GITHUB_OUTPUT
echo "plan_file_path=$PLAN_FILE_PATH" >> $GITHUB_OUTPUT

- name: Configure State AWS Credentials
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) }}
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) }}
uses: aws-actions/[email protected]
with:
aws-region: ${{ inputs.aws-region }}
Expand All @@ -139,36 +165,38 @@ runs:
mask-aws-account-id: "no"

- name: Store Plan
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) }}
uses: cloudposse/github-action-terraform-plan-storage@v1
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) }}
uses: cloudposse/github-action-terraform-plan-storage@added-commitsha-overwrite-input
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@added-commitsha-overwrite-input" isnunclear why that version change is needed. If you can move those bits to a different pr, i'm happy to get the other bits moving

id: store-plan
with:
action: storePlan
planPath: ${{ steps.atmos-plan.outputs.plan_file }}
component: ${{ inputs.component }}
stack: ${{ inputs.stack }}
commitSHA: ${{ inputs.plan-id }}
tableName: ${{ inputs.terraform-state-table }}
bucketName: ${{ inputs.terraform-state-bucket }}

- name: Store Lockfile
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) }}
uses: cloudposse/github-action-terraform-plan-storage@v1
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) }}
uses: cloudposse/github-action-terraform-plan-storage@added-commitsha-overwrite-input
with:
action: storePlan
planPath: ${{ inputs.component-path}}/.terraform.lock.hcl
component: ${{ inputs.component }}
stack: "${{ inputs.stack }}-lockfile"
commitSHA: ${{ inputs.plan-id }}
tableName: ${{ inputs.terraform-state-table }}
bucketName: ${{ inputs.terraform-state-bucket }}

- name: Setup Infracost
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(inputs.enable-infracost) }}
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) && fromJSON(inputs.enable-infracost) }}
uses: infracost/actions/setup@v2
with:
api-key: ${{ inputs.infracost-api-key }}

- name: Generate Infracost diff
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(inputs.enable-infracost) }}
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) && fromJSON(inputs.enable-infracost) }}
shell: bash
run: |
PLAN_FILE="${{ steps.atmos-plan.outputs.plan_file_path }}/${{ steps.atmos-plan.outputs.plan_file }}"
Expand All @@ -188,15 +216,15 @@ runs:
--project-name ${{ inputs.stack }}-${{ inputs.component }} \
--out-file=/tmp/infracost.json

- if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(inputs.enable-infracost) && fromJSON(inputs.debug) }}
- if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) && fromJSON(inputs.enable-infracost) && fromJSON(inputs.debug) }}
shell: bash
run: |
cat ${{ steps.atmos-plan.outputs.plan_file_path }}/${{ steps.atmos-plan.outputs.plan_file }}.json
cat /tmp/infracost.txt
cat /tmp/infracost.json

- name: Set infracost variables
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) }}
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) && fromJSON(inputs.enable-infracost) }}
id: infracost-diff
shell: bash
run: |
Expand All @@ -212,7 +240,7 @@ runs:
echo "infracost_diff_total_monthly_cost=$INFRACOST_DIFF_TOTAL_MONTHLY_COST" >> "$GITHUB_OUTPUT"

- name: Post Plan
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) }}
if: ${{ fromJSON(steps.settings.outputs.actions_enabled) && fromJSON(steps.atmos-plan.outputs.has_changes) }}
id: post-plan
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion config/atmos_github_summary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ templates:
## :x: Plan Failed for `{{.Vars.component}}` in `{{.Vars.stack}}`!
{{ end }}
{{- if eq .ExitCode 0 }}
## Plan Succeeded for `{{.Vars.component}}` in `{{.Vars.stack}}`
## Changes Found for `{{.Vars.component}}` in `{{.Vars.stack}}`

{{ if .CreatedResources}}[![create](https://shields.io/badge/PLAN-CREATE-success?style=for-the-badge)](#user-content-create-{{.Vars.stack}}-{{.Vars.component}}){{ end }}
{{- if .UpdatedResources }} [![change](https://shields.io/badge/PLAN-CHANGE-important?style=for-the-badge)](#user-content-change-{{.Vars.stack}}-{{.Vars.component}}){{ end }}
Expand Down
6 changes: 6 additions & 0 deletions docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| debug | Enable action debug mode. Default: 'false' | false | false |
| enable-infracost | Whether to enable infracost summary. Requires secret `infracost-api-key` to be specified. Default: 'false | false | false |
| infracost-api-key | Infracost API key | N/A | false |
| plan-id | Suffix that will be used for plan file name to uniquely identify it. Default: github.sha | ${{ github.sha }} | true |
| stack | The stack name for the given component. | N/A | true |
| terraform-plan-role | The AWS role to be used to plan Terraform. | N/A | true |
| terraform-state-bucket | The S3 Bucket where the planfiles are stored. | N/A | true |
Expand All @@ -20,4 +21,9 @@
| token | Used to pull node distributions for Atmos from Cloud Posse's GitHub repository. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. | ${{ github.server\_url == 'https://github.com' && github.token \|\| '' }} | false |


## Outputs

| Name | Description |
|------|-------------|
| has-changes | Has Changes |
<!-- markdownlint-restore -->