Skip to content

Commit

Permalink
fix global module need import (#28291)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 authored Jan 27, 2025
1 parent 7fa0d84 commit 96cf711
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2023-11-01/module"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -129,14 +129,11 @@ func (r PowerShell72ModuleResource) Create() sdk.ResourceFunc {
if err != nil && !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
}
if !response.WasNotFound(existing.HttpResponse) {
return metadata.ResourceRequiresImport(r.ResourceType(), id)
}

// for existing global module do update instead of raising ImportAsExistsError
isGlobal := existing.Model != nil && existing.Model.Properties != nil && existing.Model.Properties.IsGlobal != nil && *existing.Model.Properties.IsGlobal
isGlobal := existing.Model != nil && existing.Model.Properties != nil && pointer.From(existing.Model.Properties.IsGlobal)
if !response.WasNotFound(existing.HttpResponse) && !isGlobal {
return tf.ImportAsExistsError("azurerm_automation_powershell72_module", id.ID())
return metadata.ResourceRequiresImport(r.ResourceType(), id)
}

parameters := module.ModuleCreateOrUpdateParameters{
Expand Down

0 comments on commit 96cf711

Please sign in to comment.