hashicorp / hashicorp/terraform-plugin-sdk
DiffSuppressFunc on Optional integer field never sets the value
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 485
- Forks
- 244
- Avg merge
- 19h 57m
- Merged PRs (30d)
- 4
Description
SDK version
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
Relevant provider source code
func resourceExample() *schema.Resource {
return &schema.Resource{
Create: resourceExampleCreate,
Update: resourceExampleCreate,
Read: resourceExampleRead,
Delete: resourceExampleDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"requested_validity": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntInSlice([]int{7, 30, 90, 365, 730, 1095, 5475}),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return true
},
},
},
}
}
Terraform Configuration Files
resource "example" "example" {
requested_validity = 7
}
Debug Output
Expected Behavior
The requested_validity should be passed to the CRUD method as 7
Actual Behavior
The requested_validity value is passed as 0.
Steps to Reproduce
If you have a Cloudflare account you can run the acceptance tests with (email/chat me on Terraform Slack and I can give you one off credentials)
git clone https://github.com/cloudflare/terraform-provider-cloudflare.gitCLOUDFLARE_API_USER_SERVICE_KEY="xxx" CLOUDFLARE_API_KEY="xxx" CLOUDFLARE_EMAIL="xxxx" CLOUDFLARE_DOMAIN="<your_domain_here>" CLOUDFLARE_ZONE_ID="<your_zone_id_here>" TESTARGS='-run "^TestAccCloudflareOriginCACertificate_Basic" -count 1 -parallel 1' make testacc- See the test fail
- Remove
DiffSuppressFuncfrom the resource - Re-run test
- Test will pass
No Cloudflare account
- Create a new resource as documented above
- Attempt to apply the resource
- See the CRUD method is getting a zero value (not user defined)
- Remove
DiffSuppressFuncattribute - Attempt to apply the resource
- CRUD method gets correct value and works as expected
References
n/a
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided resource schema and trace how the SDK handles DiffSuppressFunc for an optional TypeInt field. Reproduce the issue using the minimal Terraform configuration or the documented acceptance-test command, comparing behavior with and without DiffSuppressFunc. Done means requested_validity reaches the CRUD method as 7 while diff suppression remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100