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

r/eventhub_namespace_authorization_rule: adding a second state migration #7622

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ func resourceArmEventHubNamespaceAuthorizationRule() *schema.Resource {
State: schema.ImportStatePassthrough,
},

SchemaVersion: 1,
SchemaVersion: 2,
StateUpgraders: []schema.StateUpgrader{
{
Type: migration.EventHubNamespaceAuthorizationRuleUpgradeV0Schema().CoreConfigSchema().ImpliedType(),
Upgrade: migration.EventHubNamespaceAuthorizationRuleUpgradeV0ToV1,
Version: 0,
},
{
Type: migration.EventHubNamespaceAuthorizationRuleUpgradeV1Schema().CoreConfigSchema().ImpliedType(),
Upgrade: migration.EventHubNamespaceAuthorizationRuleUpgradeV1ToV2,
Version: 1,
},
},

Timeouts: &schema.ResourceTimeout{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package migration

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

func EventHubNamespaceAuthorizationRuleUpgradeV1Schema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"namespace_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"resource_group_name": azure.SchemaResourceGroupName(),
},
}
}

func EventHubNamespaceAuthorizationRuleUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)

newId := strings.Replace(rawState["id"].(string), "/AuthorizationRules/", "/authorizationRules/", 1)

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

rawState["id"] = newId

return rawState, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NamespaceAuthorizationRuleID(input string) (*NamespaceAuthorizationRuleId,
return nil, err
}

if rule.Name, err = id.PopSegment("AuthorizationRules"); err != nil {
if rule.Name, err = id.PopSegment("authorizationRules"); err != nil {
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestNamespaceAuthorizationRuleID(t *testing.T) {
Error: true,
},
{
Name: "Missing AuthorizationRules Key",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/AuthorizationRules",
Name: "Missing authorizationRules Key",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/authorizationRules",
Error: true,
},
{
Name: "Namespace Authorization Rule ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/AuthorizationRules/rule1",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/authorizationRules/rule1",
Error: false,
Expect: &NamespaceAuthorizationRuleId{
ResourceGroup: "group1",
Expand All @@ -58,7 +58,7 @@ func TestNamespaceAuthorizationRuleID(t *testing.T) {
},
{
Name: "Wrong Casing",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/authorizationRules/rule1",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/AuthorizationRules/rule1",
Error: true,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d
EventHub Namespace Authorization Rules can be imported using the `resource id`, e.g.

```shell
$ terraform import azurerm_eventhub_namespace_authorization_rule.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/AuthorizationRules/rule1
$ terraform import azurerm_eventhub_namespace_authorization_rule.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/authorizationRules/rule1
```