Skip to content

Commit c7ff179

Browse files
authored
chore(docs): add notes to default tags (runatlantis#4853)
1 parent fc857f9 commit c7ff179

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

runatlantis.io/docs/custom-workflows.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,14 @@ projects:
452452

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

455-
This is only available in AWS providers [5.62.0](https://github.com/hashicorp/terraform-provider-aws/releases/tag/v5.62.0) and higher.
455+
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.
456+
457+
This configuration will create the following tags
458+
459+
* `repository` equal to `github.com/<owner>/<repo>` which can be changed for gitlab or other VCS
460+
* `repository_dir` equal to the relative directory
461+
462+
Other default variables can be added such as for workspace. See below for more available environment variables.
456463

457464
```yaml
458465
workflows:
@@ -464,7 +471,7 @@ workflows:
464471
- &env_default_tags_repository
465472
env:
466473
name: TF_AWS_DEFAULT_TAGS_repository
467-
command: 'echo "github.com/${HEAD_REPO_OWNER}/${HEAD_REPO_NAME}"'
474+
command: 'echo "github.com/${BASE_REPO_OWNER}/${BASE_REPO_NAME}"'
468475
- &env_default_tags_repository_dir
469476
env:
470477
name: TF_AWS_DEFAULT_TAGS_repository_dir
@@ -475,6 +482,31 @@ workflows:
475482
- *env_default_tags_repository_dir
476483
```
477484

485+
NOTE:
486+
- 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).
487+
- To run a local plan outside of terraform, the same environment variables will need to be created.
488+
489+
```bash
490+
tfvars () {
491+
export terraform_repository=$(git config --get remote.origin.url | sed 's,^git@,,g' | tr ':' '/' | sed 's,.git$,,g')
492+
export terraform_repository_dir=$(git rev-parse --show-prefix | sed 's,\/$,,g')
493+
}
494+
export TF_AWS_DEFAULT_TAGS_repository=$terraform_repository
495+
export TF_AWS_DEFAULT_TAGS_repository_dir=$terraform_repository_dir
496+
tfvars
497+
terraform plan
498+
```
499+
500+
If a colon is used in the tag name, use the `env` command instead of `export`.
501+
502+
```bash
503+
tfvars
504+
env \
505+
TF_AWS_DEFAULT_TAGS_org:repository=$terraform_repository \
506+
TF_AWS_DEFAULT_TAGS_org:repository_dir=$terraform_repository_dir \
507+
terraform plan
508+
```
509+
478510
## Reference
479511

480512
### Workflow

0 commit comments

Comments
 (0)