You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/technical-standards/How-to guides/tagging.md
+53-1Lines changed: 53 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,59 @@ This guide shows you how to configure tagging to meet the [tagging standard](..
4
4
5
5
## Terraform
6
6
7
-
TODO
7
+
To add consistent tags to every resource created by a particular provider within a repo, use [the `default_tags` block in your terraform provider block](https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider). This will cascade any tags you specify to all resources created by terraform. For example:
See how we use this in [LBHackney-IT/ce-dns](https://github.com/LBHackney-IT/ce-dns/blob/main/providers.tf) for a real-world example, including passing variables into the tag block.
24
+
25
+
### Dynamic tags in Terraform
26
+
27
+
Tags such as `AutomationBuildUrl` change every time we run the build in CI. Terraform doesn't support reading environment variables directly in the provider, so we need to pass these in as Terraform variables.
28
+
29
+
Here's an example for how to add `AutomationBuildUrl`:
30
+
31
+
1. Create a variable to hold the value in `variables.tf`:
32
+
> ℹ️ We use snake_case for variable names to match the Terraform convention
33
+
```hcl
34
+
variable "automation_build_url" {
35
+
description = "The URL of the CI build that deployed or modified this infrastructure"
36
+
type = string
37
+
nullable = false
38
+
}
39
+
```
40
+
41
+
2. Use the environment variable in `providers.tf` where you're defining your tags:
42
+
```hcl
43
+
provider "aws" {
44
+
default_tags {
45
+
# ...
46
+
AutomationBuildUrl: var.automation_build_url
47
+
}
48
+
```
49
+
50
+
3. Then reference the environment variables in `tfvars/production.tfvars`, `tfvars/staging.tfvars`, and any other environments you have.
0 commit comments