Skip to content

Commit

Permalink
Migrating servicebus auth rule ID (#17824)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaxyi authored Aug 16, 2022
1 parent 266953e commit 4c724ee
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
98 changes: 98 additions & 0 deletions internal/services/servicebus/migration/namespace_auth_rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package migration

import (
"context"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

var _ pluginsdk.StateUpgrade = ServicebusNamespaceAuthRuleV0ToV1{}

type ServicebusNamespaceAuthRuleV0ToV1 struct{}

func (ServicebusNamespaceAuthRuleV0ToV1) Schema() map[string]*pluginsdk.Schema {
s := map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
//lintignore: S013
"namespace_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},

"listen": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"send": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"manage": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"primary_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"primary_connection_string": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"primary_connection_string_alias": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string_alias": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
}
return s
}

func (ServicebusNamespaceAuthRuleV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {

oldID := rawState["id"].(string)

id, err := namespacesauthorizationrule.ParseAuthorizationRuleIDInsensitively(oldID)
if err != nil {
return nil, err
}
rawState["id"] = id.ID()

return rawState, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand All @@ -34,6 +35,11 @@ func resourceServiceBusNamespaceAuthorizationRule() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(30 * time.Minute),
},

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

// function takes a schema map and adds the authorization rule properties to it
Schema: resourceServiceBusNamespaceAuthorizationRuleSchema(),

Expand Down

0 comments on commit 4c724ee

Please sign in to comment.