Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Mar 21, 2023
1 parent 1694ead commit 00b3e7d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func TestKeyResourceV0ToV1(t *testing.T) {
},
expected: utils.String("/subscriptions/12345678-1234-5678-1234-123456789012/resourcegroups/resourceGroup1/providers/Microsoft.AppConfiguration/configurationStores/appConf1/AppConfigurationKey/key:name/test/Label/test:label/name"),
},
{
name: "old id (this is a bug and should be fixed in v1 to v2)",
input: map[string]interface{}{
"id": "/subscriptions/12345678-1234-5678-1234-123456789012/resourcegroups/resourceGroup1/providers/Microsoft.AppConfiguration/configurationStores/appConf1/AppConfigurationKey/keyName/Label/%00",
},
expected: utils.String("/subscriptions/12345678-1234-5678-1234-123456789012/resourcegroups/resourceGroup1/providers/Microsoft.AppConfiguration/configurationStores/appConf1/AppConfigurationKey/keyName/Label/\000/AppConfigurationKey/keyName/Label/"),
},
}
for _, test := range testData {
t.Logf("Testing %q...", test.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func (KeyResourceV1ToV2) UpgradeFunc() pluginsdk.StateUpgraderFunc {
oldId := rawState["id"].(string)
fixedId := oldId

// if the ID is like below, it should be bugs for no-label, see https://github.com/hashicorp/terraform-provider-azurerm/issues/20849
// /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.AppConfiguration/configurationStores/appConf1/AppConfigurationKey/appConfKey1/Label/\000/AppConfigurationKey/appConfKey1/Label/
if index1, index2 := strings.Index(fixedId, "/AppConfigurationKey/"), strings.LastIndex(fixedId, "/AppConfigurationKey/"); index1 != index2 && fixedId[index2-1] == '\000' && fixedId[index1:index2-1] == fixedId[index2:] {
fixedId = fixedId[:index2]
}

if strings.HasSuffix(fixedId, "/Label/\000") {
fixedId = strings.TrimSuffix(fixedId, "/Label/\000") + "/Label/%00"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func TestKeyResourceV1ToV2(t *testing.T) {
},
expected: utils.String("https://appConf1.azconfig.io/kv/keyName?label="),
},
{
name: "old id (fix bug with no-label)",
input: map[string]interface{}{
"id": "/subscriptions/12345678-1234-5678-1234-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.AppConfiguration/configurationStores/appConf1/AppConfigurationKey/keyName/Label/\000/AppConfigurationKey/keyName/Label/",
},
expected: utils.String("https://appConf1.azconfig.io/kv/keyName?label="),
},
}
for _, test := range testData {
t.Logf("Testing %q...", test.name)
Expand Down

0 comments on commit 00b3e7d

Please sign in to comment.