diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go index 03b4d22a16ad..2a26651d4c7a 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go @@ -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{ diff --git a/azurerm/internal/services/eventhub/migration/namespace_authorization_rule_v1.go b/azurerm/internal/services/eventhub/migration/namespace_authorization_rule_v1.go new file mode 100644 index 000000000000..605cebb0d03a --- /dev/null +++ b/azurerm/internal/services/eventhub/migration/namespace_authorization_rule_v1.go @@ -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 +} diff --git a/azurerm/internal/services/eventhub/parse/namespace_authorization_rule.go b/azurerm/internal/services/eventhub/parse/namespace_authorization_rule.go index fe5c0442f964..c3453785a204 100644 --- a/azurerm/internal/services/eventhub/parse/namespace_authorization_rule.go +++ b/azurerm/internal/services/eventhub/parse/namespace_authorization_rule.go @@ -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 } diff --git a/azurerm/internal/services/eventhub/parse/namespace_authorization_rule_test.go b/azurerm/internal/services/eventhub/parse/namespace_authorization_rule_test.go index 3723d78076fe..eae18be19847 100644 --- a/azurerm/internal/services/eventhub/parse/namespace_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/parse/namespace_authorization_rule_test.go @@ -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", @@ -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, }, } diff --git a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown index ddc5ae515195..77e40c70b550 100644 --- a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown +++ b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown @@ -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 ```