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

chore(docs): add notes to default tags #4853

Merged
merged 2 commits into from
Aug 31, 2024
Merged
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
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
Loading