Skip to content

Commit

Permalink
hashicorp#7310 state v2 to lowercase authorizationRules
Browse files Browse the repository at this point in the history
  • Loading branch information
Everton Macedo committed Jul 8, 2020
1 parent 3d7e105 commit 0f0894f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
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
@@ -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
}
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
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 Down
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
```

0 comments on commit 0f0894f

Please sign in to comment.