Skip to content

Commit aed593d

Browse files
authored
azurerm_api_management_api_operation : exclude the leading * when extracting the name list from the url_template property (#29895)
[BUG] * `azurerm_api_management_api_operation` - fix validation for the `url_template` property to allow parameters prefixed with `*`
1 parent 36be11d commit aed593d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

internal/services/apimanagement/api_management_api_operation_resource.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"log"
1010
"regexp"
11+
"strings"
1112
"time"
1213

1314
"github.com/hashicorp/go-azure-helpers/lang/pointer"
@@ -122,7 +123,8 @@ func resourceApiManagementApiOperation() *pluginsdk.Resource {
122123
urlTemplateParamSet := make(map[string]struct{})
123124
for _, match := range matches {
124125
if len(match) > 1 {
125-
urlTemplateParamSet[match[1]] = struct{}{}
126+
// Since Azure API Management's `url_template` supports two formats: {name} and {*name}, `*` should be removed when getting name.
127+
urlTemplateParamSet[strings.TrimPrefix(match[1], "*")] = struct{}{}
126128
}
127129
}
128130

internal/services/apimanagement/api_management_api_operation_resource_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ func TestAccApiManagementApiOperation_templateParameter(t *testing.T) {
136136
),
137137
},
138138
data.ImportStep(),
139+
{
140+
Config: r.templateParameterUpdate(data),
141+
Check: acceptance.ComposeTestCheckFunc(
142+
check.That(data.ResourceName).ExistsInAzure(r),
143+
),
144+
},
145+
data.ImportStep(),
139146
})
140147
}
141148

@@ -593,6 +600,33 @@ resource "azurerm_api_management_api_operation" "test" {
593600
`, r.template(data))
594601
}
595602

603+
func (r ApiManagementApiOperationResource) templateParameterUpdate(data acceptance.TestData) string {
604+
return fmt.Sprintf(`
605+
%s
606+
607+
resource "azurerm_api_management_api_operation" "test" {
608+
operation_id = "acctest-operation"
609+
api_name = azurerm_api_management_api.test.name
610+
api_management_name = azurerm_api_management.test.name
611+
resource_group_name = azurerm_resource_group.test.name
612+
display_name = "Acceptance Test Operation"
613+
method = "DELETE"
614+
url_template = "/{*path}"
615+
description = "This can only be done by the logged in user."
616+
617+
template_parameter {
618+
name = "path"
619+
type = "string"
620+
required = true
621+
}
622+
623+
response {
624+
status_code = 200
625+
}
626+
}
627+
`, r.template(data))
628+
}
629+
596630
func (ApiManagementApiOperationResource) template(data acceptance.TestData) string {
597631
return fmt.Sprintf(`
598632
provider "azurerm" {

0 commit comments

Comments
 (0)