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

Move to GitOps Config File #29

Merged
merged 21 commits into from
Dec 13, 2023
53 changes: 37 additions & 16 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@ jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Plan Atmos Component
uses: cloudposse/github-action-atmos-terraform-plan@main
with:
component: "foobar"
stack: "plat-ue2-sandbox"
component-path: "components/terraform/foobar"
terraform-plan-role: ${{ secrets.TERRAFORM_APPLY_ROLE }}
terraform-state-role: ${{ secrets.TERRAFORM_STATE_ROLE }}
- shell: bash
run: |
mkdir -p ${{ runner.temp }}
cat > ${{ runner.temp }}/atmos-gitops.yaml <<EOL
atmos-version: 1.45.3
atmos-config-path: ./tests/
terraform-state-bucket: ${{ secrets.TERRAFORM_STATE_BUCKET }}
terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }}
terraform-version: "1.5.2"
terraform-state-role: ${{ secrets.TERRAFORM_STATE_ROLE }}
terraform-plan-role: ${{ secrets.TERRAFORM_APPLY_ROLE }}
terraform-version: 1.5.2
aws-region: ${{ env.AWS_REGION }}
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
EOL

- name: Plan Atmos Component
uses: cloudposse/github-action-atmos-terraform-plan@incapsulate-configs
with:
component: "foobar"
stack: "plat-ue2-sandbox"
atmos-gitops-config-path: "${{ runner.temp }}/atmos-gitops.yaml"
test:
runs-on: ubuntu-latest
needs: setup
Expand All @@ -39,15 +48,27 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}

- shell: bash
run: |
mkdir -p ${{ runner.temp }}
cat > ${{ runner.temp }}/atmos-gitops.yaml <<EOL
atmos-version: 1.45.3
atmos-config-path: ./tests/
terraform-state-bucket: ${{ secrets.TERRAFORM_STATE_BUCKET }}
terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }}
terraform-state-role: ${{ secrets.TERRAFORM_STATE_ROLE }}
terraform-plan-role: ${{ secrets.TERRAFORM_APPLY_ROLE }}
terraform-apply-role: ${{ secrets.TERRAFORM_APPLY_ROLE }}
terraform-version: 1.5.2
aws-region: ${{ env.AWS_REGION }}
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
EOL

- name: Apply Atmos Component
uses: ./
with:
component: "foobar"
stack: "plat-ue2-sandbox"
component-path: "components/terraform/foobar"
terraform-apply-role: ${{ secrets.TERRAFORM_APPLY_ROLE }}
terraform-state-role: ${{ secrets.TERRAFORM_STATE_ROLE }}
terraform-state-bucket: ${{ secrets.TERRAFORM_STATE_BUCKET }}
terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }}
terraform-version: "1.5.2"
aws-region: ${{ env.AWS_REGION }}
atmos-gitops-config-path: "${{ runner.temp }}/atmos-gitops.yaml"
debug: true
243 changes: 110 additions & 133 deletions README.md

Large diffs are not rendered by default.

79 changes: 69 additions & 10 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,29 @@ usage: |-
to allow GitHub to assume roles in AWS and then deploying both a Terraform Apply role and a Terraform State role.
For Cloud Posse documentation on setting up GitHub OIDC, see our [`github-oidc-provider` component](https://docs.cloudposse.com/components/library/aws/github-oidc-provider/).

In order to retrieve Terraform State, we configure an S3 Bucket to store plan files and a DynamoDB table to track plan metadata. Both will need to be deployed before running
this action. For more on setting up those components, see the `gitops` component (__documentation pending__). This action will then use the [github-action-terraform-plan-storage](https://github.com/cloudposse/github-action-terraform-plan-storage) action to update these resources.
In order to retrieve Terraform Plan Files (not to be confused with Terraform State files, e.g. `tfstate`), we configure an S3 Bucket to store plan files and a DynamoDB table to track plan metadata. Both need to be deployed before running
this action. For more on setting up those components, see the [`gitops` component](https://docs.cloudposse.com/components/library/aws/gitops/). This action will then use the [github-action-terraform-plan-storage](https://github.com/cloudposse/github-action-terraform-plan-storage) action to update these resources.

### Config

The action expects the atmos gitops configuration file to be present in the repository in `./.github/config/atmos-gitops.yaml`.
The config should have the following structure:

```yaml
atmos-version: 1.45.3
atmos-config-path: ./rootfs/usr/local/etc/atmos/
terraform-state-bucket: cptest-core-ue2-auto-gitops
terraform-state-table: cptest-core-ue2-auto-gitops
Comment on lines +64 to +65
Copy link
Member

Choose a reason for hiding this comment

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

We have to rename these. These are not for the Terraform State Bucket. These are for the Terraform Plan File.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's add this task to the backlog

Choose a reason for hiding this comment

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

terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's add this task to the backlog

Choose a reason for hiding this comment

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

terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
terraform-version: 1.5.2
aws-region: us-east-2
enable-infracost: false
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
```

### Workflow example

```yaml
Expand All @@ -75,20 +95,59 @@ usage: |-
plan:
runs-on: ubuntu-latest
steps:
- name: Plan Atmos Component
uses: cloudposse/github-action-atmos-terraform-apply@v1
- name: Terraform Apply
uses: cloudposse/github-action-atmos-terraform-apply@v2
with:
component: "foobar"
stack: "plat-ue2-sandbox"
component-path: "components/terraform/s3-bucket"
terraform-apply-role: "arn:aws:iam::111111111111:role/acme-core-gbl-identity-gitops"
terraform-state-bucket: "acme-core-ue2-auto-gitops"
terraform-state-role: "arn:aws:iam::999999999999:role/acme-core-ue2-auto-gitops-gha"
terraform-state-table: "acme-core-ue2-auto-gitops"
aws-region: "us-east-2"
```

### Migrating from `v1` to `v2`

1. `v2` drops the `component-path` variable and instead fetches if directly from the [`atmos.yaml` file](https://atmos.tools/cli/configuration/) automatically. Simply remove the `component-path` argument from your invocations of the `cloudposse/github-action-atmos-terraform-apply` action.
2. `v2` moves most of the `inputs` to the Atmos GitOps config path `./.github/config/atmos-gitops.yaml`. Simply create this file, transfer your settings to it, then remove the corresponding arguments from your invocations of the `cloudposse/github-action-atmos-terraform-apply` action.
| name |
|--------------------------|
| `atmos-version` |
| `atmos-config-path` |
| `terraform-state-bucket` |
| `terraform-state-table` |
| `terraform-state-role` |
| `terraform-plan-role` |
| `terraform-apply-role` |
| `terraform-version` |
| `aws-region` |
| `enable-infracost` |


If you want the same behavior in `v2` as in `v1` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v1` inputs.

```yaml
- name: Terraform apply
uses: cloudposse/github-action-atmos-terraform-apply@v2
with:
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
component: "foobar"
stack: "plat-ue2-sandbox"
```

Which would produce the same behavior as in `v1`, doing this:

```yaml
- name: Terraform apply
uses: cloudposse/github-action-atmos-terraform-apply@v1
with:
component: "foobar"
stack: "plat-ue2-sandbox"
component-path: "components/terraform/s3-bucket"
terraform-apply-role: "arn:aws:iam::111111111111:role/acme-core-gbl-identity-gitops"
terraform-state-bucket: "acme-core-ue2-auto-gitops"
terraform-state-role: "arn:aws:iam::999999999999:role/acme-core-ue2-auto-gitops-gha"
terraform-state-table: "acme-core-ue2-auto-gitops"
aws-region: "us-east-2"
```


include:
- "docs/github-action.md"

Expand Down
Loading
Loading