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

helper/schema: Ensure (ResourceData).GetRawConfig() is populated in provider Configure functions #1271

Merged
merged 3 commits into from
Nov 9, 2023

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Nov 2, 2023

Closes #1270

This change is intended to be as targeted as possible to prevent other unintended changes. In other RPCs, the protocol configuration data is able to be set upfront via terraform.InstanceState, however for provider configuration it is still using the legacy terraform.ResourceConfig value which previously did not have the same data field. This adds the data field while trying to be pragmatic about potentially breaking compatibility with the unfortunately exported APIs in this SDK.

This change also tangentially fixes GetOkExists to now return a true second result when a configuration

New test failures prior to updating logic:

--- FAIL: TestProviderConfigure (0.00s)
    --- FAIL: TestProviderConfigure/ConfigureContextFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:338: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetRawConfig difference: expected: {{{{} map[test:{{{"...}},
              )
    --- FAIL: TestProviderConfigure/ConfigureFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:338: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetRawConfig difference: expected: {{{{} map[test:{{{"...}},
              )

--- FAIL: TestGRPCProviderServerConfigureProvider (0.00s)
    --- FAIL: TestGRPCProviderServerConfigureProvider/ConfigureContextFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider_test.go:343: unexpected difference:   &tfprotov5.ConfigureProviderResponse{
            - 	Diagnostics: []*tfprotov5.Diagnostic{
            - 		&{
            - 			Severity: s"ERROR",
            - 			Summary:  "unexpected difference: expected: {{{{} map[test:{{{} %!s(cty.pri"...,
            - 		},
            - 	},
            + 	Diagnostics: nil,
              }
    --- FAIL: TestGRPCProviderServerConfigureProvider/ConfigureFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider_test.go:343: unexpected difference:   &tfprotov5.ConfigureProviderResponse{
            - 	Diagnostics: []*tfprotov5.Diagnostic{
            - 		&{
            - 			Severity: s"ERROR",
            - 			Summary:  "unexpected difference: expected: {{{{} map[test:{{{} %!s(cty.pri"...,
            - 		},
            - 	},
            + 	Diagnostics: nil,
              }

In terms of prior (errant) GetOkExists() behavior, this causes this behavior change/fix:

--- FAIL: TestProviderConfigure (0.00s)
    --- FAIL: TestProviderConfigure/ConfigureContextFunc-GetOkExists-zero-value (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:924: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetOkExists difference: expected: false, got: true"}},
              )
    --- FAIL: TestProviderConfigure/ConfigureFunc-GetOkExists-zero-value (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:924: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetOkExists difference: expected: false, got: true"}},
              )

…rovider Configure functions

Reference: #1270

This change is intended to be as targeted as possible to prevent other unintended changes. In other RPCs, the protocol configuration data is able to be set upfront via `terraform.InstanceState`, however for provider configuration it is still using the legacy `terraform.ResourceConfig` value which previously did not have the same data field. This adds the data field while trying to be pragmatic about potentially breaking compatibility with the unfortunately exported APIs in this SDK.

New test failures prior to updating logic:

```
--- FAIL: TestProviderConfigure (0.00s)
    --- FAIL: TestProviderConfigure/ConfigureContextFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:338: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetRawConfig difference: expected: {{{{} map[test:{{{"...}},
              )
    --- FAIL: TestProviderConfigure/ConfigureFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:338: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetRawConfig difference: expected: {{{{} map[test:{{{"...}},
              )

--- FAIL: TestGRPCProviderServerConfigureProvider (0.00s)
    --- FAIL: TestGRPCProviderServerConfigureProvider/ConfigureContextFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider_test.go:343: unexpected difference:   &tfprotov5.ConfigureProviderResponse{
            - 	Diagnostics: []*tfprotov5.Diagnostic{
            - 		&{
            - 			Severity: s"ERROR",
            - 			Summary:  "unexpected difference: expected: {{{{} map[test:{{{} %!s(cty.pri"...,
            - 		},
            - 	},
            + 	Diagnostics: nil,
              }
    --- FAIL: TestGRPCProviderServerConfigureProvider/ConfigureFunc-GetRawConfig (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider_test.go:343: unexpected difference:   &tfprotov5.ConfigureProviderResponse{
            - 	Diagnostics: []*tfprotov5.Diagnostic{
            - 		&{
            - 			Severity: s"ERROR",
            - 			Summary:  "unexpected difference: expected: {{{{} map[test:{{{} %!s(cty.pri"...,
            - 		},
            - 	},
            + 	Diagnostics: nil,
              }
```
@bflad bflad added the bug Something isn't working label Nov 2, 2023
@bflad bflad requested a review from a team as a code owner November 2, 2023 10:39
@bflad bflad added this to the v2.30.0 milestone Nov 2, 2023
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, one general question, the linked issue also mentions GetRawPlan and GetRawState, are we going to eventually populate those as well?

This change also fixes `GetOkExists()` handling for provider configuration.

Updated tests prior to logic updates:

```
--- FAIL: TestProviderConfigure (0.00s)
    --- FAIL: TestProviderConfigure/ConfigureContextFunc-GetOkExists-zero-value (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:924: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetOkExists difference: expected: false, got: true"}},
              )
    --- FAIL: TestProviderConfigure/ConfigureFunc-GetOkExists-zero-value (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider_test.go:924: Unexpected diagnostics (-wanted +got):   diag.Diagnostics(
            - 	nil,
            + 	{{Summary: "unexpected GetOkExists difference: expected: false, got: true"}},
              )
```
@bflad
Copy link
Contributor Author

bflad commented Nov 6, 2023

one general question, the linked issue also mentions GetRawPlan and GetRawState, are we going to eventually populate those as well?

Provider configuration only contains configuration data. It does not participate in the plan (similar to data sources) nor does Terraform preserve a prior state.

This verifies it is safe to always set the `ResourceConfig` regardless of the presence of `InstanceDiff`, ensuring that `GetOkExists()` should work in both cases without affecting existing behavior.
@bflad bflad merged commit 8130d59 into main Nov 9, 2023
6 checks passed
@bflad bflad deleted the bflad/provider-configure-GetRawConfig branch November 9, 2023 10:15
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Dec 10, 2023
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
Development

Successfully merging this pull request may close these issues.

schema.ResourceData.GetRaw<whatever>() not populated during provider configuration
2 participants