From bbad8ae09cfeb2a3d7899722ac5ae77660c1c6cb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 27 Jun 2022 11:10:26 +0200 Subject: [PATCH] portal: refactoring to account for the updated ID structures --- .../portal_tenant_configuration_resource.go | 21 +++++++++++-------- ...rtal_tenant_configuration_resource_test.go | 7 ++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/services/portal/portal_tenant_configuration_resource.go b/internal/services/portal/portal_tenant_configuration_resource.go index 8910132df821..cf4d1c9ea792 100644 --- a/internal/services/portal/portal_tenant_configuration_resource.go +++ b/internal/services/portal/portal_tenant_configuration_resource.go @@ -5,6 +5,8 @@ import ( "log" "time" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/portal/parse" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/portal/2019-01-01-preview/tenantconfiguration" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -30,7 +32,7 @@ func resourcePortalTenantConfiguration() *pluginsdk.Resource { }, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := tenantconfiguration.ParseConfigurationID(id) + _, err := parse.PortalTenantConfigurationID(id) return err }), @@ -48,10 +50,11 @@ func resourcePortalTenantConfigurationCreateUpdate(d *pluginsdk.ResourceData, me ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := tenantconfiguration.NewConfigurationID("default") - + // NOTE: we're using a Terraform-internal Resource ID here since the Go SDK no longer exposes one + // since this is an operation on a Tenant (which doesn't expose any configurable values). + id := parse.NewPortalTenantConfigurationID("default") if d.IsNewResource() { - existing, err := client.TenantConfigurationsGet(ctx, id) + existing, err := client.TenantConfigurationsGet(ctx) if err != nil { if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for existing %s: %+v", id, err) @@ -69,7 +72,7 @@ func resourcePortalTenantConfigurationCreateUpdate(d *pluginsdk.ResourceData, me }, } - if _, err := client.TenantConfigurationsCreate(ctx, id, parameters); err != nil { + if _, err := client.TenantConfigurationsCreate(ctx, parameters); err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } @@ -83,12 +86,12 @@ func resourcePortalTenantConfigurationRead(d *pluginsdk.ResourceData, meta inter ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := tenantconfiguration.ParseConfigurationID(d.Id()) + id, err := parse.PortalTenantConfigurationID(d.Id()) if err != nil { return err } - resp, err := client.TenantConfigurationsGet(ctx, *id) + resp, err := client.TenantConfigurationsGet(ctx) if err != nil { if response.WasNotFound(resp.HttpResponse) { log.Printf("[INFO] %s was not found - removing from state!", *id) @@ -112,12 +115,12 @@ func resourcePortalTenantConfigurationDelete(d *pluginsdk.ResourceData, meta int ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := tenantconfiguration.ParseConfigurationID(d.Id()) + id, err := parse.PortalTenantConfigurationID(d.Id()) if err != nil { return err } - if _, err := client.TenantConfigurationsDelete(ctx, *id); err != nil { + if _, err := client.TenantConfigurationsDelete(ctx); err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } diff --git a/internal/services/portal/portal_tenant_configuration_resource_test.go b/internal/services/portal/portal_tenant_configuration_resource_test.go index 0cc5118f10a5..18018cfea151 100644 --- a/internal/services/portal/portal_tenant_configuration_resource_test.go +++ b/internal/services/portal/portal_tenant_configuration_resource_test.go @@ -5,7 +5,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/go-azure-sdk/resource-manager/portal/2019-01-01-preview/tenantconfiguration" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/portal/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -77,12 +78,12 @@ func testAccPortalTenantConfiguration_update(t *testing.T) { } func (r PortalTenantConfigurationResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := tenantconfiguration.ParseConfigurationID(state.ID) + id, err := parse.PortalTenantConfigurationID(state.ID) if err != nil { return nil, err } - resp, err := client.Portal.TenantConfigurationsClient.TenantConfigurationsGet(ctx, *id) + resp, err := client.Portal.TenantConfigurationsClient.TenantConfigurationsGet(ctx) if err != nil { return nil, fmt.Errorf("retrieving %s: %v", *id, err) }