hashicorp / hashicorp/terraform-plugin-sdk
StateFunc not being applied to TypeMap Elem values.
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
### SDK version
```
v2.4.4
```
(But a quick look at v2.5.0's schema.go suggests that the behavior has not changed)
### Relevant provider source code
```go
// Basically, any property of type `TypeMap`, whose `Elem` has a `StateFunc`.
"rules_event_rules_jsons": {
Description: "JSON schema for Track Properties, keyed by name.",
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
StateFunc: canonicalizeSchemaRulesJSON,
},
},
```
### Terraform Configuration Files
```hcl
// Basically, HCL that populates the "rules_event_rules_jsons" defined above with a map from arbitrary keys, to JSON
```
### Debug Output
### Expected Behavior
We are populating a `TypeMap` property in a "configMap" with JSON values that is equivalent to the "stateMap" value, but not identical. To ensure that diffs are not detected, we define a `StateFunc` whose purpose is to canonicalize the JSON such that equivalent JSONs become identical.
When running `terraform plan`, we do not expect diffs to be detected given two equivalent JSON.
### Actual Behavior
Diffs are being detected.
### Steps to Reproduce
### References
We are aware we are able to use a DiffSupressionFunc to suppress the diff, however this is less than ideal for us, as when a genuine diff is detected, the reported diff ends up being much larger than it should be (as it would included other diffs previously suppressed by the function).
Contributor guide
Research direction
Start in schema.go, focusing on how TypeMap handles an Elem schema with a StateFunc. Reproduce the issue with equivalent JSON values in a map, then verify that canonicalized values no longer produce plan diffs while genuine differences remain visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100