Skip to content

Commit

Permalink
chore(docs): add notes to default tags (#4853)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocode authored Aug 31, 2024
1 parent fc857f9 commit c7ff179
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions runatlantis.io/docs/custom-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,14 @@ projects:

### Add directory and repo context for aws resources using default tags

This is only available in AWS providers [5.62.0](https://github.com/hashicorp/terraform-provider-aws/releases/tag/v5.62.0) and higher.
This is only available in AWS provider version [5.62.0](https://github.com/hashicorp/terraform-provider-aws/releases/tag/v5.62.0) and higher.

This configuration will create the following tags

* `repository` equal to `github.com/<owner>/<repo>` which can be changed for gitlab or other VCS
* `repository_dir` equal to the relative directory

Other default variables can be added such as for workspace. See below for more available environment variables.

```yaml
workflows:
Expand All @@ -464,7 +471,7 @@ workflows:
- &env_default_tags_repository
env:
name: TF_AWS_DEFAULT_TAGS_repository
command: 'echo "github.com/${HEAD_REPO_OWNER}/${HEAD_REPO_NAME}"'
command: 'echo "github.com/${BASE_REPO_OWNER}/${BASE_REPO_NAME}"'
- &env_default_tags_repository_dir
env:
name: TF_AWS_DEFAULT_TAGS_repository_dir
Expand All @@ -475,6 +482,31 @@ workflows:
- *env_default_tags_repository_dir
```

NOTE:
- Appending tags to every resource may regenerate data sources such as `aws_iam_policy_document` which will cause many resources to be modified. See known issue in aws provider [#29421](https://github.com/hashicorp/terraform-provider-aws/issues/29421).
- To run a local plan outside of terraform, the same environment variables will need to be created.

```bash
tfvars () {
export terraform_repository=$(git config --get remote.origin.url | sed 's,^git@,,g' | tr ':' '/' | sed 's,.git$,,g')
export terraform_repository_dir=$(git rev-parse --show-prefix | sed 's,\/$,,g')
}
export TF_AWS_DEFAULT_TAGS_repository=$terraform_repository
export TF_AWS_DEFAULT_TAGS_repository_dir=$terraform_repository_dir
tfvars
terraform plan
```

If a colon is used in the tag name, use the `env` command instead of `export`.

```bash
tfvars
env \
TF_AWS_DEFAULT_TAGS_org:repository=$terraform_repository \
TF_AWS_DEFAULT_TAGS_org:repository_dir=$terraform_repository_dir \
terraform plan
```

## Reference

### Workflow
Expand Down

0 comments on commit c7ff179

Please sign in to comment.