Skip to content

Commit

Permalink
fix app conf feature no label update (#19900)
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed Jan 9, 2023
1 parent 17a9687 commit 7f8cd8e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ func TestAccAppConfigurationFeature_requiresImport(t *testing.T) {
})
}

func TestAccAppConfigurationFeature_noLabelUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_configuration_feature", "test")
r := AppConfigurationFeatureResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicNoLabel(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateNoLabel(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAppConfigurationFeature_lockUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_configuration_feature", "test")
r := AppConfigurationFeatureResource{}
Expand Down Expand Up @@ -272,6 +293,46 @@ resource "azurerm_app_configuration_feature" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (t AppConfigurationFeatureResource) updateNoLabel(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-appconfig-%d"
location = "%s"
}
data "azurerm_client_config" "test" {
}
resource "azurerm_role_assignment" "test" {
scope = azurerm_resource_group.test.id
role_definition_name = "App Configuration Data Owner"
principal_id = data.azurerm_client_config.test.object_id
}
resource "azurerm_app_configuration" "test" {
name = "testacc-appconf%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
depends_on = [
azurerm_role_assignment.test,
]
}
resource "azurerm_app_configuration_feature" "test" {
configuration_store_id = azurerm_app_configuration.test.id
description = "test description"
name = "acctest-ackey-%d"
enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (t AppConfigurationFeatureResource) basicWithSlash(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func handleSlashInIdForFeature(input string) string {
}

oldNames = regexp.MustCompile(`AppConfigurationFeature\/.+\/Label\/(.+)`).FindStringSubmatch(input)
if len(oldNames) == 2 {

// Label will have a "%00" placeholder if we're dealing with an empty label,
if len(oldNames) == 2 && oldNames[1] != "%00" {
input = strings.Replace(input, oldNames[1], url.QueryEscape(oldNames[1]), 1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func handleSlashInIdForKey(input string) string {
}

oldNames = regexp.MustCompile(`AppConfigurationKey\/.+\/Label\/(.+)`).FindStringSubmatch(input)
if len(oldNames) == 2 {

// Label will have a "%00" placeholder if we're dealing with an empty label,
if len(oldNames) == 2 && oldNames[1] != "%00" {
input = strings.Replace(input, oldNames[1], url.QueryEscape(oldNames[1]), 1)
}

Expand Down

0 comments on commit 7f8cd8e

Please sign in to comment.