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: website/docs/language/tests/mocking.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,19 +105,19 @@ Mocked providers only generate data for computed attributes. All required resour
105
105
106
106
An example of this is the `bucket` attribute in the `aws_s3_bucket` resource. A real AWS provider will generate a bucket name if one is not specified. A mocked AWS provider will do the same, and only generate a value if one is not already specified in the configuration.
107
107
108
-
By default, Terraform will generate data during the `apply` operation while returning`(known after apply)` values during the `plan` operation. This behavior can be overridden with the `override_during` attribute in the `mock_provider` block:
108
+
By default, Terraform generates data during the `apply` operation and returns`(known after apply)` values during the `plan` operation. You can override this behavior with the `override_during` attribute in the `mock_provider` block:
109
109
110
110
```hcl
111
111
mock_provider "aws" {
112
112
override_during = plan
113
113
}
114
114
```
115
115
116
-
The above `aws` provider will generate the data during the `plan` operation and reuse the same data during the `apply` operation. The `override_during` attribute accepts either `plan` or `apply` as values.
116
+
The above `aws` provider generates the data during the `plan` operation and reuses the same data during the `apply` operation. The `override_during` attribute accepts either `plan` or `apply` as values.
117
117
118
118
### Mock Provider data
119
119
120
-
You can specify specific values for targeted resources and data sources. in a `mock_provider` block, you can write any number of `mock_resource` and `mock_data` blocks. Both the `mock_resource` and `mock_data` blocks accept a type argument that should match the resource or data source you want to provide values for. They also accept a `defaults` object attribute that you can use to specify the values that should be returned for specific attributes.
120
+
You can specify specific values for targeted resources and data sources. In a `mock_provider` block, you can write any number of `mock_resource` and `mock_data` blocks. Both the `mock_resource` and `mock_data` blocks accept a type argument that should match the resource or data source you want to provide values for. They also accept a `defaults` object attribute that you can use to specify the values that should be returned for specific attributes.
121
121
122
122
The following example demonstrates providing a set `arn` value for all AWS S3 bucket resources and data sources:
123
123
@@ -137,7 +137,7 @@ mock_provider "aws" {
137
137
}
138
138
```
139
139
140
-
In the above example, Terraform uses the supplied value for `arn` attributes in S3 buckets instead of generating a random string. Computed attributes not provided an explicit default will simply fall back to the generic data generation rules. The `override_during` attribute can also be used in the `mock_resource` and `mock_data` blocks to specify when the values should be generated at an individual resource level. If not specified, the values will be generated using the rules inherited from the `mock_provider` block. If specified, the local value will override any value specified in the `mock_provider` block.
140
+
In the above example, Terraform uses the supplied value for `arn` attributes in S3 buckets instead of generating a random string. Computed attributes not provided an explicit default will simply fall back to the generic data generation rules. You can also use the `override_during` attribute in the `mock_resource` and `mock_data` blocks to specify when Terraform should generate the values for an individual resource. If you do not not specify the `override_during` attribute, Terraform generates the values using the rules inherited from the `mock_provider` block. If specified, the local value overrides any value specified in the `mock_provider` block.
141
141
142
142
You can also share mock provider data between tests by writing dedicated mock data files and using the `source` attribute in the `mock_provider` block. Mock data files have `.tfmock.hcl` or `.tfmock.json` extension, and can contain `mock_resource` and `mock_data` blocks as if they were defined in the `mock_provider` block directly.
143
143
@@ -181,9 +181,9 @@ Overrides can be used with both real and mocked providers and will provide the c
181
181
182
182
### Overrides Syntax
183
183
184
-
All override blocks contain a `target` attribute, which should specify the resource, data source, or module to override. The `override_module` blocks contain an `outputs` attribute, while the `override_resource` and `override_data` blocks contain a `values` attribute. In addition, the override blocks also support the same `override_during` attribute seen within the `mock_provider` block.
184
+
All override blocks contain a `target` attribute, which should specify the resource, data source, or module to override. The `override_module` blocks contain an `outputs` attribute, while the `override_resource` and `override_data` blocks contain a `values` attribute. The override blocks also support the `override_during` attribute.
185
185
186
-
The `outputs` and `values` attributes are optional and if not specified, Terraform will generate values for them automatically. The `override_during` attribute is also optional, and if specified it will override the `override_during` attribute in the `mock_provider` block. If not specified, the behavior will be inherited from the `mock_provider` block.
186
+
The `outputs` and `values` attributes are optional and if not specified, Terraform will generate values for them automatically. The `override_during` attribute is also optional, and if specified it will override the `override_during` attribute in the `mock_provider` block. If not specified, Terraform inherits the behavior from the `mock_provider` block.
187
187
188
188
The following example demonstrates the override blocks at various different scopes and levels. The main configuration calls the `./modules/s3_data` module to read a file from an S3 bucket, and then creates a `local_file` from the data returned from the module.
0 commit comments