Skip to content

Commit f9e2f7c

Browse files
authored
Add provider example to terraform applying (#36965)
1 parent 7c81522 commit f9e2f7c

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
page_title: terraform.applying reference - Functions - Configuration Language
3-
description: |-
4-
The terraform.applying symbol enables you to determine if Terraform is currently running an apply operation.
2+
page_title: terraform.applying reference - Functions - Configuration Language
3+
description: |-
4+
The terraform.applying symbol enables you to determine if Terraform is currently running an apply operation.
55
---
66

77
# The `terraform.applying` symbol
@@ -12,23 +12,33 @@ You can use the `terraform.applying` symbol in your configuration to determine i
1212

1313
Terraform automatically sets `terraform.applying` to `true` when you run an [apply](/terraform/cli/commands/apply) operation, and `false` during any other operation. The [planning mode](/terraform/cli/commands/plan#planning-modes) you run `terraform apply` in does not affect `terraform.applying`, meaning that even in destroy mode, `terraform.applying` is still `true`.
1414

15-
A common example of where `terraform.applying` can be helpful is when you want to use different credentials if Terraform is either planning or applying.
15+
You can use `terraform.applying` to change Terraform behavior during apply operations. In the following example, Terraform uses your read-only credentials when running a plan operation but uses your write credentials when you run an apply operation:
1616

1717
```hcl
1818
locals {
1919
aws_read_role_arn = "arn:aws:iam::XXXXX:role/terraform-read"
2020
aws_write_role_arn = "arn:aws:iam::XXXXX:role/terraform-full"
2121
22-
# We only need read-only credentials to plan, so if Terraform is applying
23-
# we want to use our AWS role that allows us to write.
2422
role_arn = terraform.applying ? local.aws_write_role_arn : local.aws_read_role_arn
2523
}
24+
25+
provider "aws" {
26+
region = "us-west-2"
27+
28+
assume_role {
29+
role_arn = local.role_arn
30+
}
31+
}
32+
2633
```
2734

28-
The `terraform.applying` symbol is an ephemeral value, meaning it is only available during Terraform operations and Terraform does not write this value to plan or state files. Additionally, you can only reference `terraform.applying` in ephemeral contexts:
2935

30-
* In a [write-only argument](/terraform/language/resources/ephemeral/write-only)
31-
* In [ephemeral variables](/terraform/language/values/variables#exclude-values-from-state)
32-
* In [local values](/terraform/language/values/locals#ephemeral-values)
33-
* In [ephemeral resources](/terraform/language/resources/ephemeral)
34-
* In [ephemeral outputs](/terraform/language/values/outputs#ephemeral-avoid-storing-values-in-state-or-plan-files)
36+
The `terraform.applying` symbol is an ephemeral value and is only available during Terraform operations. Terraform does not write ephemeral values to plan or state files. Additionally, you can only reference `terraform.applying` in the following ephemeral contexts:
37+
38+
- In a [write-only argument](/terraform/language/resources/ephemeral/write-only)
39+
- In [ephemeral variables](/terraform/language/values/variables#exclude-values-from-state)
40+
- In [local values](/terraform/language/values/locals#ephemeral-values)
41+
- In [ephemeral resources](/terraform/language/resources/ephemeral)
42+
- In [ephemeral outputs](/terraform/language/values/outputs#ephemeral-avoid-storing-values-in-state-or-plan-files)
43+
- Configuring providers in the `provider` block
44+
- In [provisioner](/terraform/language/resources/provisioners/syntax) and [connection](/terraform/language/resources/provisioners/connection) blocks

0 commit comments

Comments
 (0)