Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_management_group_subscription_association - add migration for SDK update #27461

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package migration

import (
"context"
"log"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/managementgroup/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

var _ pluginsdk.StateUpgrade = ManagementGroupSubscriptionAssociationV0ToV1{}

type ManagementGroupSubscriptionAssociationV0ToV1 struct{}

func (ManagementGroupSubscriptionAssociationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)
newId := strings.Replace(strings.Replace(rawState["id"].(string), "/managementGroup/", "/providers/Microsoft.Management/managementGroups/", 1), "/subscription/", "/subscriptions/", 1)

log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId)

rawState["id"] = newId

return rawState, nil
}
}

func (ManagementGroupSubscriptionAssociationV0ToV1) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"management_group_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ManagementGroupID,
},

"subscription_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: commonids.ValidateSubscriptionID,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/managementgroups/2020-05-01/managementgroups"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/managementgroup/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/managementgroup/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/managementgroup/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand All @@ -28,6 +29,11 @@ func resourceManagementGroupSubscriptionAssociation() *pluginsdk.Resource {
Read: resourceManagementGroupSubscriptionAssociationRead,
Delete: resourceManagementGroupSubscriptionAssociationDelete,

SchemaVersion: 1,
StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{
0: migration.ManagementGroupSubscriptionAssociationV0ToV1{},
}),

Timeouts: &pluginsdk.ResourceTimeout{
Create: pluginsdk.DefaultTimeout(5 * time.Minute),
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l
Managements can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_management_group_subscription_association.example /managementGroup/MyManagementGroup/subscription/12345678-1234-1234-1234-123456789012
terraform import azurerm_management_group_subscription_association.example /providers/Microsoft.Management/managementGroups/MyManagementGroup/subscriptions/12345678-1234-1234-1234-123456789012
```
Loading