Skip to content

Commit

Permalink
portal: refactoring to account for the updated ID structures
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jun 27, 2022
1 parent be51587 commit bbad8ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions internal/services/portal/portal_tenant_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}),

Expand All @@ -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)
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit bbad8ae

Please sign in to comment.