Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.EnvDefaultFunc doesn't work with int resource attributes #773

Closed
rudo-thomas opened this issue Jun 23, 2021 · 2 comments · Fixed by #841
Closed

schema.EnvDefaultFunc doesn't work with int resource attributes #773

rudo-thomas opened this issue Jun 23, 2021 · 2 comments · Fixed by #841
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rudo-thomas
Copy link
Contributor

schema.EnvDefaultFunc doesn't work when used as DefaultFunc on a TypeInt resource attribute; works fine with TypeString, TypeBool, TypeFloat attributes.

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.6.1

Steps to Reproduce

Run go test in this repository: https://github.com/rudo-thomas/terraform-sdk-default-int-from-env-bug (a snapshot at b3f1b82 is
attached).

Relevant provider source code

"i": &schema.Schema{
	Type:        schema.TypeInt,
	Optional:    true,
	DefaultFunc: schema.EnvDefaultFunc("SOME_VAR", nil),
}

Expected Behavior

The test should pass.

Actual Behavior

Error: Attribute must be a whole number, got 1

Note: The 1 in the error message is of string type, which I found out by printing the type at

Summary: fmt.Sprintf("Attribute must be a whole number, got %v", raw),

Workaround

To work this around, the DefaultFunc set in the Schema can wrap schema.EnvDefaultFunc(...)() and convert the string to an int.

@rudo-thomas rudo-thomas added the bug Something isn't working label Jun 23, 2021
rudo-thomas added a commit to rudo-thomas/terraform-plugin-sdk that referenced this issue Jan 7, 2022
This brings the int field up to par with bool and float ones.

Fixes hashicorp#773
@rudo-thomas
Copy link
Contributor Author

PR #841 fixes this on main (past v2.10.1).

@bflad bflad self-assigned this Mar 24, 2022
@bflad bflad added this to the v2.13.0 milestone Mar 24, 2022
bflad pushed a commit that referenced this issue Mar 24, 2022
… DefaultFunc(). (#841)

This brings the int field up to par with bool and float ones.

Fixes #773
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
2 participants