From 0cb47cab2f3b6435dab1644d9926a38aa7456d38 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Fri, 13 Jan 2023 11:07:31 +0000 Subject: [PATCH 1/3] Update Hamilton to v0.54.0 --- go.mod | 2 +- go.sum | 4 ++-- .../manicminer/hamilton/environments/published.go | 1 + vendor/github.com/manicminer/hamilton/msgraph/models.go | 1 + vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go | 6 +++--- vendor/modules.txt | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 28ba5e82cd..1d9864b776 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 - github.com/manicminer/hamilton v0.52.0 + github.com/manicminer/hamilton v0.54.0 golang.org/x/text v0.3.7 ) diff --git a/go.sum b/go.sum index 754ea32e03..20f48092ff 100644 --- a/go.sum +++ b/go.sum @@ -224,8 +224,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/manicminer/hamilton v0.52.0 h1:z+K/fxTpCtWi/XMB4L9QgqPo2B+eoYozNeh8YvplJ3I= -github.com/manicminer/hamilton v0.52.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk= +github.com/manicminer/hamilton v0.54.0 h1:vnjgE7Eer9dnrAd78qZHPK6CTNCwwFmuVtvBjjl4OtY= +github.com/manicminer/hamilton v0.54.0/go.mod h1:lbVyngC+/nCWuDp8UhC6Bw+bh7jcP/E+YwqzHTmzemk= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= diff --git a/vendor/github.com/manicminer/hamilton/environments/published.go b/vendor/github.com/manicminer/hamilton/environments/published.go index 2d1944f779..23deeb47f3 100644 --- a/vendor/github.com/manicminer/hamilton/environments/published.go +++ b/vendor/github.com/manicminer/hamilton/environments/published.go @@ -79,6 +79,7 @@ var PublishedApis = map[string]ApiAppId{ "MicrosoftAzureFrontDoorCdn": "205478c0-bd83-4e1b-a9d6-db63a3e1e1c8", "Microsoft365DataAtRestEncryption": "c066d759-24ae-40e7-a56f-027002b5d3e4", "MicrosoftGraph": "00000003-0000-0000-c000-000000000000", + "Microsoft.StorageSync": "9469b9f5-6722-4481-a2b2-14ed560b706f", "MicrosoftInvoicing": "b6b84568-6c01-4981-a80f-09da9a20bbed", "Office365Connectors": "48af08dc-f6d2-435f-b2a7-069abd99c086", "Office365Demeter": "982bda36-4632-4165-a46a-9863b1bbcf7d", diff --git a/vendor/github.com/manicminer/hamilton/msgraph/models.go b/vendor/github.com/manicminer/hamilton/msgraph/models.go index 735b8af57c..b1c70c4d55 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/models.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/models.go @@ -202,6 +202,7 @@ type Application struct { CreatedDateTime *time.Time `json:"createdDateTime,omitempty"` DefaultRedirectUri *string `json:"defaultRedirectUri,omitempty"` DeletedDateTime *time.Time `json:"deletedDateTime,omitempty"` + Description *StringNullWhenEmpty `json:"description,omitempty"` DisabledByMicrosoftStatus interface{} `json:"disabledByMicrosoftStatus,omitempty"` DisplayName *string `json:"displayName,omitempty"` GroupMembershipClaims *[]GroupMembershipClaim `json:"-"` // see Application.MarshalJSON / Application.UnmarshalJSON diff --git a/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go b/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go index 4364ba530d..11206c42b8 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go @@ -451,9 +451,9 @@ const ( type OnPremisesGroupType = string const ( - UniversalDistributionGroup OnPremisesGroupType = "universalDistributionGroup" - UniversalMailEnabledSecurityGroup OnPremisesGroupType = "universalMailEnabledSecurityGroup" - UniversalSecurityGroup OnPremisesGroupType = "universalSecurityGroup" + UniversalDistributionGroup OnPremisesGroupType = "UniversalDistributionGroup" + UniversalMailEnabledSecurityGroup OnPremisesGroupType = "UniversalMailEnabledSecurityGroup" + UniversalSecurityGroup OnPremisesGroupType = "UniversalSecurityGroup" ) type Members []DirectoryObject diff --git a/vendor/modules.txt b/vendor/modules.txt index bf561b68c9..18d94b83fc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -151,7 +151,7 @@ github.com/hashicorp/terraform-svchost # github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 ## explicit; go 1.15 github.com/hashicorp/yamux -# github.com/manicminer/hamilton v0.52.0 +# github.com/manicminer/hamilton v0.54.0 ## explicit; go 1.16 github.com/manicminer/hamilton/auth github.com/manicminer/hamilton/environments From cfd09d7c26b91f131a2c41a0fe0fc17cd46a3a83 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Fri, 13 Jan 2023 11:07:56 +0000 Subject: [PATCH 2/3] `azuread_application` - support the `description` property --- internal/services/applications/application_resource.go | 10 ++++++++++ .../services/applications/application_resource_test.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/internal/services/applications/application_resource.go b/internal/services/applications/application_resource.go index 48dd82e17a..75234cb746 100644 --- a/internal/services/applications/application_resource.go +++ b/internal/services/applications/application_resource.go @@ -258,6 +258,13 @@ func applicationResource() *schema.Resource { }, }, + "description": { + Description: "Description of the application as shown to end users", + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: validate.ValidateDiag(validation.StringLenBetween(0, 1024)), + }, + "device_only_auth_enabled": { Description: "Specifies whether this application supports device authentication without a user.", Type: schema.TypeBool, @@ -951,6 +958,7 @@ func applicationResourceCreate(ctx context.Context, d *schema.ResourceData, meta properties := msgraph.Application{ Api: expandApplicationApi(d.Get("api").([]interface{})), AppRoles: expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List()), + Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(tempDisplayName), GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*schema.Set).List()), IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*schema.Set).List()), @@ -1121,6 +1129,7 @@ func applicationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta }, Api: expandApplicationApi(d.Get("api").([]interface{})), AppRoles: expandApplicationAppRoles(d.Get("app_role").(*schema.Set).List()), + Description: utils.NullableString(d.Get("description").(string)), DisplayName: utils.String(displayName), GroupMembershipClaims: expandApplicationGroupMembershipClaims(d.Get("group_membership_claims").(*schema.Set).List()), IdentifierUris: tf.ExpandStringSlicePtr(d.Get("identifier_uris").(*schema.Set).List()), @@ -1217,6 +1226,7 @@ func applicationResourceRead(ctx context.Context, d *schema.ResourceData, meta i tf.Set(d, "app_role", flattenApplicationAppRoles(app.AppRoles)) tf.Set(d, "app_role_ids", flattenApplicationAppRoleIDs(app.AppRoles)) tf.Set(d, "application_id", app.AppId) + tf.Set(d, "description", app.Description) tf.Set(d, "device_only_auth_enabled", app.IsDeviceOnlyAuthSupported) tf.Set(d, "disabled_by_microsoft", fmt.Sprintf("%v", app.DisabledByMicrosoftStatus)) tf.Set(d, "display_name", app.DisplayName) diff --git a/internal/services/applications/application_resource_test.go b/internal/services/applications/application_resource_test.go index 4dac53439b..0da9927cb0 100644 --- a/internal/services/applications/application_resource_test.go +++ b/internal/services/applications/application_resource_test.go @@ -666,6 +666,7 @@ resource "azuread_application" "test" { fallback_public_client_enabled = true oauth2_post_response_required = true + description = "Acceptance testing application" marketing_url = "https://hashitown-%[1]d.com/" privacy_statement_url = "https://hashitown-%[1]d.com/privacy" support_url = "https://support.hashitown-%[1]d.com/" @@ -850,6 +851,7 @@ resource "azuread_application" "test" { fallback_public_client_enabled = true oauth2_post_response_required = true + description = "Acceptance testing application" marketing_url = "https://templatetown-%[1]d.com/" privacy_statement_url = "https://templatetown-%[1]d.com/privacy" support_url = "https://support.templatetown-%[1]d.com/" From 451c0ae7f02df0d12943a22d1a809e5a663174d5 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Fri, 13 Jan 2023 11:19:20 +0000 Subject: [PATCH 3/3] Downgrade terraform-plugin-sdk/v2 to v2.24.0 due to early context cancellation --- go.mod | 2 +- go.sum | 4 +- .../v2/helper/logging/logging.go | 7 ++-- .../v2/helper/resource/plugin.go | 29 +++------------ .../v2/helper/resource/testcase_providers.go | 6 +-- .../v2/helper/resource/testing.go | 10 ----- .../v2/helper/resource/testing_new.go | 6 +-- .../resource/testing_new_import_state.go | 16 +++----- .../v2/helper/resource/teststep_providers.go | 37 ++++--------------- .../v2/internal/plugintest/config.go | 3 +- .../v2/internal/plugintest/helper.go | 5 ++- .../v2/internal/plugintest/working_dir.go | 25 ++++++++----- vendor/modules.txt | 2 +- 13 files changed, 52 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index 1d9864b776..afccc91299 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/hashicorp/terraform-provider-azuread require ( github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-uuid v1.0.3 - github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 github.com/manicminer/hamilton v0.54.0 golang.org/x/text v0.3.7 ) diff --git a/go.sum b/go.sum index 20f48092ff..cfeb12609b 100644 --- a/go.sum +++ b/go.sum @@ -194,8 +194,8 @@ github.com/hashicorp/terraform-plugin-go v0.14.1 h1:cwZzPYla82XwAqpLhSzdVsOMU+6H github.com/hashicorp/terraform-plugin-go v0.14.1/go.mod h1:Bc/K6K26BQ2FHqIELPbpKtt2CzzbQou+0UQF3/0NsCQ= github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs= github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 h1:zHcMbxY0+rFO9gY99elV/XC/UnQVg7FhRCbj1i5b7vM= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1/go.mod h1:+tNlb0wkfdsDJ7JEiERLz4HzM19HyiuIoGzTsM7rPpw= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging/logging.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging/logging.go index 74eb7f6667..235586aed8 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging/logging.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging/logging.go @@ -3,6 +3,7 @@ package logging import ( "fmt" "io" + "io/ioutil" "log" "os" "strings" @@ -31,7 +32,7 @@ var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"} // environment variable. Calls to tflog.* will have their output managed by the // tfsdklog sink. func LogOutput(t testing.T) (logOutput io.Writer, err error) { - logOutput = io.Discard + logOutput = ioutil.Discard logLevel := LogLevel() if logLevel == "" { @@ -87,7 +88,7 @@ func LogOutput(t testing.T) (logOutput io.Writer, err error) { // SetOutput checks for a log destination with LogOutput, and calls // log.SetOutput with the result. If LogOutput returns nil, SetOutput uses -// io.Discard. Any error from LogOutout is fatal. +// ioutil.Discard. Any error from LogOutout is fatal. func SetOutput(t testing.T) { out, err := LogOutput(t) if err != nil { @@ -95,7 +96,7 @@ func SetOutput(t testing.T) { } if out == nil { - out = io.Discard + out = ioutil.Discard } log.SetOutput(out) diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/plugin.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/plugin.go index 120f04276b..9e52348d69 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/plugin.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/plugin.go @@ -3,7 +3,7 @@ package resource import ( "context" "fmt" - "io" + "io/ioutil" "os" "strings" "sync" @@ -157,13 +157,6 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl host = v } - // schema.Provider have a global stop context that is created outside - // the server context and have their own associated goroutine. Since - // Terraform does not call the StopProvider RPC to stop the server in - // reattach mode, ensure that we save these servers to later call that - // RPC and end those goroutines. - legacyProviderServers := make([]*schema.GRPCProviderServer, 0, len(factories.legacy)) - // Spin up gRPC servers for every provider factory, start a // WaitGroup to listen for all of the close channels. var wg sync.WaitGroup @@ -187,24 +180,18 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl // shut down. wg.Add(1) - grpcProviderServer := schema.NewGRPCProviderServer(provider) - legacyProviderServers = append(legacyProviderServers, grpcProviderServer) - - // Ensure StopProvider is always called when returning early. - defer grpcProviderServer.StopProvider(ctx, nil) //nolint:errcheck // does not return errors - // configure the settings our plugin will be served with // the GRPCProviderFunc wraps a non-gRPC provider server // into a gRPC interface, and the logger just discards logs // from go-plugin. opts := &plugin.ServeOpts{ GRPCProviderFunc: func() tfprotov5.ProviderServer { - return grpcProviderServer + return schema.NewGRPCProviderServer(provider) }, Logger: hclog.New(&hclog.LoggerOptions{ Name: "plugintest", Level: hclog.Trace, - Output: io.Discard, + Output: ioutil.Discard, }), NoLogOutputOverride: true, UseTFLogSink: t, @@ -292,7 +279,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl Logger: hclog.New(&hclog.LoggerOptions{ Name: "plugintest", Level: hclog.Trace, - Output: io.Discard, + Output: ioutil.Discard, }), NoLogOutputOverride: true, UseTFLogSink: t, @@ -377,7 +364,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl Logger: hclog.New(&hclog.LoggerOptions{ Name: "plugintest", Level: hclog.Trace, - Output: io.Discard, + Output: ioutil.Discard, }), NoLogOutputOverride: true, UseTFLogSink: t, @@ -443,12 +430,6 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl // get closed, and we'll hang here. cancel() - // For legacy providers, call the StopProvider RPC so the StopContext - // goroutine is cleaned up properly. - for _, legacyProviderServer := range legacyProviderServers { - legacyProviderServer.StopProvider(ctx, nil) //nolint:errcheck // does not return errors - } - logging.HelperResourceTrace(ctx, "Waiting for providers to stop") // wait for the servers to actually shut down; it may take a moment for diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testcase_providers.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testcase_providers.go index 19a548cdb1..c09e4657cc 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testcase_providers.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testcase_providers.go @@ -9,7 +9,7 @@ import ( // providerConfig takes the list of providers in a TestCase and returns a // config with only empty provider blocks. This is useful for Import, where no // config is provided, but the providers must be defined. -func (c TestCase) providerConfig(_ context.Context, skipProviderBlock bool) string { +func (c TestCase) providerConfig(_ context.Context) string { var providerBlocks, requiredProviderBlocks strings.Builder // [BF] The Providers field handling predates the logic being moved to this @@ -21,9 +21,7 @@ func (c TestCase) providerConfig(_ context.Context, skipProviderBlock bool) stri } for name, externalProvider := range c.ExternalProviders { - if !skipProviderBlock { - providerBlocks.WriteString(fmt.Sprintf("provider %q {}\n", name)) - } + providerBlocks.WriteString(fmt.Sprintf("provider %q {}\n", name)) if externalProvider.Source == "" && externalProvider.VersionConstraint == "" { continue diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing.go index caadc3ddc5..c77f0629ac 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing.go @@ -551,16 +551,6 @@ type TestStep struct { // ImportStateCheck checks the results of ImportState. It should be // used to verify that the resulting value of ImportState has the // proper resources, IDs, and attributes. - // - // Prefer ImportStateVerify over ImportStateCheck, unless the resource - // import explicitly is expected to create multiple resources (not a - // recommended resource implementation) or if attributes are imported with - // syntactically different but semantically/functionally equivalent values - // where special logic is needed. - // - // Terraform versions 1.3 and later can include data source states during - // import, which the testing framework will skip to prevent the need for - // Terraform version specific logic in provider testing. ImportStateCheck ImportStateCheckFunc // ImportStateVerify, if true, will also check that the state values diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new.go index 007ab66c0d..6fa78c23ec 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new.go @@ -89,7 +89,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest }() if c.hasProviders(ctx) { - err := wd.SetConfig(ctx, c.providerConfig(ctx, false)) + err := wd.SetConfig(ctx, c.providerConfig(ctx)) if err != nil { logging.HelperResourceError(ctx, @@ -170,7 +170,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest protov6: protov6ProviderFactories(c.ProtoV6ProviderFactories).merge(step.ProtoV6ProviderFactories), } - providerCfg := step.providerConfig(ctx, step.configHasProviderBlock(ctx)) + providerCfg := step.providerConfig(ctx) err := wd.SetConfig(ctx, providerCfg) @@ -371,7 +371,7 @@ func testIDRefresh(ctx context.Context, t testing.T, c TestCase, wd *plugintest. // Temporarily set the config to a minimal provider config for the refresh // test. After the refresh we can reset it. - err := wd.SetConfig(ctx, c.providerConfig(ctx, step.configHasProviderBlock(ctx))) + err := wd.SetConfig(ctx, c.providerConfig(ctx)) if err != nil { t.Fatalf("Error setting import test config: %s", err) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new_import_state.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new_import_state.go index 0ec007168b..17b4c2add4 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new_import_state.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/testing_new_import_state.go @@ -137,18 +137,12 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest logging.HelperResourceTrace(ctx, "Using TestStep ImportStateCheck") var states []*terraform.InstanceState - for address, r := range importState.RootModule().Resources { - if strings.HasPrefix(address, "data.") { - continue + for _, r := range importState.RootModule().Resources { + if r.Primary != nil { + is := r.Primary.DeepCopy() + is.Ephemeral.Type = r.Type // otherwise the check function cannot see the type + states = append(states, is) } - - if r.Primary == nil { - continue - } - - is := r.Primary.DeepCopy() - is.Ephemeral.Type = r.Type // otherwise the check function cannot see the type - states = append(states, is) } logging.HelperResourceDebug(ctx, "Calling TestStep ImportStateCheck") diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/teststep_providers.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/teststep_providers.go index 757f8f638c..b3c71b8c01 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/teststep_providers.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource/teststep_providers.go @@ -3,24 +3,9 @@ package resource import ( "context" "fmt" - "regexp" "strings" ) -var configProviderBlockRegex = regexp.MustCompile(`provider "?[a-zA-Z0-9_-]+"? {`) - -// configHasProviderBlock returns true if the Config has declared a provider -// configuration block, e.g. provider "examplecloud" {...} -func (s TestStep) configHasProviderBlock(_ context.Context) bool { - return configProviderBlockRegex.MatchString(s.Config) -} - -// configHasTerraformBlock returns true if the Config has declared a terraform -// configuration block, e.g. terraform {...} -func (s TestStep) configHasTerraformBlock(_ context.Context) bool { - return strings.Contains(s.Config, "terraform {") -} - // mergedConfig prepends any necessary terraform configuration blocks to the // TestStep Config. // @@ -33,16 +18,12 @@ func (s TestStep) mergedConfig(ctx context.Context, testCase TestCase) string { // Prevent issues with existing configurations containing the terraform // configuration block. - if s.configHasTerraformBlock(ctx) { - config.WriteString(s.Config) - - return config.String() - } - - if testCase.hasProviders(ctx) { - config.WriteString(testCase.providerConfig(ctx, s.configHasProviderBlock(ctx))) - } else { - config.WriteString(s.providerConfig(ctx, s.configHasProviderBlock(ctx))) + if !strings.Contains(s.Config, "terraform {") { + if testCase.hasProviders(ctx) { + config.WriteString(testCase.providerConfig(ctx)) + } else { + config.WriteString(s.providerConfig(ctx)) + } } config.WriteString(s.Config) @@ -53,13 +34,11 @@ func (s TestStep) mergedConfig(ctx context.Context, testCase TestCase) string { // providerConfig takes the list of providers in a TestStep and returns a // config with only empty provider blocks. This is useful for Import, where no // config is provided, but the providers must be defined. -func (s TestStep) providerConfig(_ context.Context, skipProviderBlock bool) string { +func (s TestStep) providerConfig(_ context.Context) string { var providerBlocks, requiredProviderBlocks strings.Builder for name, externalProvider := range s.ExternalProviders { - if !skipProviderBlock { - providerBlocks.WriteString(fmt.Sprintf("provider %q {}\n", name)) - } + providerBlocks.WriteString(fmt.Sprintf("provider %q {}\n", name)) if externalProvider.Source == "" && externalProvider.VersionConstraint == "" { continue diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/config.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/config.go index 920c471655..c238145aaa 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/config.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/config.go @@ -3,6 +3,7 @@ package plugintest import ( "context" "fmt" + "io/ioutil" "os" "strings" @@ -34,7 +35,7 @@ func DiscoverConfig(ctx context.Context, sourceDir string) (*Config, error) { tfPath := os.Getenv(EnvTfAccTerraformPath) tempDir := os.Getenv(EnvTfAccTempDir) - tfDir, err := os.MkdirTemp(tempDir, "plugintest-terraform") + tfDir, err := ioutil.TempDir(tempDir, "plugintest-terraform") if err != nil { return nil, fmt.Errorf("failed to create temp dir: %w", err) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/helper.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/helper.go index bfe89e1b9e..0411eae0a8 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/helper.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/helper.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io/ioutil" "os" "strings" @@ -69,7 +70,7 @@ func AutoInitHelper(ctx context.Context, sourceDir string) (*Helper, error) { // automatically clean those up. func InitHelper(ctx context.Context, config *Config) (*Helper, error) { tempDir := os.Getenv(EnvTfAccTempDir) - baseDir, err := os.MkdirTemp(tempDir, "plugintest") + baseDir, err := ioutil.TempDir(tempDir, "plugintest") if err != nil { return nil, fmt.Errorf("failed to create temporary directory for test helper: %s", err) } @@ -104,7 +105,7 @@ func (h *Helper) Close() error { // program exits, the Close method on the helper itself will attempt to // delete it. func (h *Helper) NewWorkingDir(ctx context.Context, t TestControl) (*WorkingDir, error) { - dir, err := os.MkdirTemp(h.baseDir, "work") + dir, err := ioutil.TempDir(h.baseDir, "work") if err != nil { return nil, err } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/working_dir.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/working_dir.go index 159399350f..123a7ed119 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/working_dir.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest/working_dir.go @@ -1,9 +1,11 @@ package plugintest import ( + "bytes" "context" "encoding/json" "fmt" + "io/ioutil" "os" "path/filepath" @@ -85,7 +87,7 @@ func (wd *WorkingDir) SetConfig(ctx context.Context, cfg string) error { if err := os.Remove(rmFilename); err != nil && !os.IsNotExist(err) { return fmt.Errorf("unable to remove %q: %w", rmFilename, err) } - err := os.WriteFile(outFilename, bCfg, 0700) + err := ioutil.WriteFile(outFilename, bCfg, 0700) if err != nil { return err } @@ -279,11 +281,11 @@ func (wd *WorkingDir) SavedPlan(ctx context.Context) (*tfjson.Plan, error) { return nil, fmt.Errorf("there is no current saved plan") } - logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command for JSON plan") + logging.HelperResourceTrace(ctx, "Calling Terraform CLI apply command") plan, err := wd.tf.ShowPlanFile(context.Background(), wd.planFilename(), tfexec.Reattach(wd.reattachInfo)) - logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command for JSON plan") + logging.HelperResourceTrace(ctx, "Calling Terraform CLI apply command") return plan, err } @@ -297,17 +299,22 @@ func (wd *WorkingDir) SavedPlanRawStdout(ctx context.Context) (string, error) { return "", fmt.Errorf("there is no current saved plan") } - logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command for stdout plan") + var ret bytes.Buffer + + wd.tf.SetStdout(&ret) + defer wd.tf.SetStdout(ioutil.Discard) + + logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command") - stdout, err := wd.tf.ShowPlanFileRaw(context.Background(), wd.planFilename(), tfexec.Reattach(wd.reattachInfo)) + _, err := wd.tf.ShowPlanFileRaw(context.Background(), wd.planFilename(), tfexec.Reattach(wd.reattachInfo)) - logging.HelperResourceTrace(ctx, "Called Terraform CLI show command for stdout plan") + logging.HelperResourceTrace(ctx, "Called Terraform CLI show command") if err != nil { return "", err } - return stdout, nil + return ret.String(), nil } // State returns an object describing the current state. @@ -315,11 +322,11 @@ func (wd *WorkingDir) SavedPlanRawStdout(ctx context.Context) (string, error) { // If the state cannot be read, State returns an error. func (wd *WorkingDir) State(ctx context.Context) (*tfjson.State, error) { - logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command for JSON state") + logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command") state, err := wd.tf.Show(context.Background(), tfexec.Reattach(wd.reattachInfo)) - logging.HelperResourceTrace(ctx, "Called Terraform CLI show command for JSON state") + logging.HelperResourceTrace(ctx, "Called Terraform CLI show command") return state, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 18d94b83fc..73b2674f07 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -121,7 +121,7 @@ github.com/hashicorp/terraform-plugin-log/internal/hclogutils github.com/hashicorp/terraform-plugin-log/internal/logging github.com/hashicorp/terraform-plugin-log/tflog github.com/hashicorp/terraform-plugin-log/tfsdklog -# github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 +# github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 ## explicit; go 1.18 github.com/hashicorp/terraform-plugin-sdk/v2/diag github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest