hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
436 stars 231 forks source link

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

Closed bflad closed 11 months ago

bflad commented 11 months ago

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"}},
              )
bflad commented 11 months ago

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.

github-actions[bot] commented 10 months ago

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.