Skip to content

Commit 304b473

Browse files
authored
Merge pull request #1154 from erhancagirici/apimanager-subscription-external-name-fix
fix: add displayName parameter to Subscription.apimanager
2 parents c0b493a + 3e1cabf commit 304b473

17 files changed

Lines changed: 127 additions & 19 deletions

File tree

apis/cluster/apimanagement/v1beta1/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/cluster/apimanagement/v1beta1/zz_subscription_types.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/namespaced/apimanagement/v1beta1/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/namespaced/apimanagement/v1beta1/zz_subscription_types.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/cluster/cache/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func Configure(p *config.Provider) {
2424
})
2525

2626
p.AddResourceConfigurator("azurerm_redis_cache", func(r *config.Resource) {
27-
config.MarkAsRequired(r.TerraformResource, "redis_version")
27+
r.MarkAsRequired("redis_version")
2828
})
2929
}

config/externalname.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ var TerraformPluginSDKExternalNameConfigs = map[string]config.ExternalName{
118118
"azurerm_api_management_redis_cache": config.TemplatedStringAsIdentifier("name", "{{ .parameters.api_management_id }}/caches/{{ .external_name }}"),
119119
// API Management Subscriptions can be imported using the resource id
120120
// /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ApiManagement/service/example-apim/subscriptions/subscription-name
121-
"azurerm_api_management_subscription": config.TemplatedStringAsIdentifier("display_name", "/subscriptions/{{ .setup.configuration.subscription_id }}/resourceGroups/{{ .parameters.resource_group_name }}/providers/Microsoft.ApiManagement/service/{{ .parameters.api_management_name }}/subscriptions/{{ .external_name }}"),
121+
"azurerm_api_management_subscription": apiManagementSubscription(),
122122
// API Management Tags can be imported using the resource id
123123
// /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/tags/tag1
124124
"azurerm_api_management_tag": config.TemplatedStringAsIdentifier("name", "{{ .parameters.api_management_id }}/tags/{{ .external_name }}"),
@@ -2396,6 +2396,32 @@ func policyDefinitionExternalName(resourceType string) config.ExternalName {
23962396
}
23972397
}
23982398

2399+
func apiManagementSubscription() config.ExternalName {
2400+
e := config.TemplatedStringAsIdentifier("", "/subscriptions/{{ .setup.configuration.subscription_id }}/resourceGroups/{{ .parameters.resource_group_name }}/providers/Microsoft.ApiManagement/service/{{ .parameters.api_management_name }}/subscriptions/{{ .external_name }}")
2401+
templatedGetIDFn := e.GetIDFn
2402+
e.SetIdentifierArgumentFn = func(base map[string]any, externalName string) {
2403+
if len(externalName) == 0 {
2404+
return
2405+
}
2406+
if subId, ok := base["subscription_id"].(string); !ok || subId == "" {
2407+
base["subscription_id"] = externalName
2408+
}
2409+
// backward-compatible behavior for existing resources with
2410+
// no spec.forProvider.displayName set.
2411+
if displayName, ok := base["display_name"].(string); !ok || displayName == "" {
2412+
base["display_name"] = externalName
2413+
}
2414+
}
2415+
e.GetIDFn = func(ctx context.Context, externalName string, parameters map[string]any, terraformProviderConfig map[string]any) (string, error) {
2416+
if externalName == "" {
2417+
return "", nil
2418+
}
2419+
return templatedGetIDFn(ctx, externalName, parameters, terraformProviderConfig)
2420+
}
2421+
e.DisableNameInitializer = true
2422+
return e
2423+
}
2424+
23992425
// ResourceConfigurator applies all external name configs
24002426
// listed in the table TerraformPluginSDKExternalNameConfigs and
24012427
// CLIReconciledExternalNameConfigs and sets the version

config/namespaced/cache/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func Configure(p *config.Provider) {
2424
})
2525

2626
p.AddResourceConfigurator("azurerm_redis_cache", func(r *config.Resource) {
27-
config.MarkAsRequired(r.TerraformResource, "redis_version")
27+
r.MarkAsRequired("redis_version")
2828
})
2929
}

examples-generated/cluster/apimanagement/v1beta1/subscription.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
apiManagementNameSelector:
1616
matchLabels:
1717
testing.upbound.io/example-name: azurerm_api_management
18+
displayName: Parser API
1819
productIdSelector:
1920
matchLabels:
2021
testing.upbound.io/example-name: azurerm_api_management_product

examples-generated/namespaced/apimanagement/v1beta1/subscription.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ spec:
1616
apiManagementNameSelector:
1717
matchLabels:
1818
testing.upbound.io/example-name: azurerm_api_management
19+
displayName: Parser API
1920
productIdSelector:
2021
matchLabels:
2122
testing.upbound.io/example-name: azurerm_api_management_product

examples/apimanagement/cluster/v1beta1/subscription.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ metadata:
1212
name: example
1313
spec:
1414
forProvider:
15+
displayName: "Example apim Subscription"
1516
apiManagementNameSelector:
1617
matchLabels:
1718
testing.upbound.io/example-name: example
@@ -75,11 +76,11 @@ metadata:
7576
meta.upbound.io/example-id: apimanagement/v1beta1/subscription
7677
labels:
7778
testing.upbound.io/example-name: example
78-
name: uptest-management-example
79+
name: uptest-apim-management-example
7980
spec:
8081
forProvider:
8182
location: West Europe
82-
publisherEmail: company@terraform.io
83+
publisherEmail: company@crossplane.io
8384
publisherName: My Company
8485
resourceGroupNameSelector:
8586
matchLabels:
@@ -93,7 +94,7 @@ metadata:
9394
meta.upbound.io/example-id: apimanagement/v1beta1/subscription
9495
labels:
9596
testing.upbound.io/example-name: example
96-
name: uptest-resourcegroup-example
97+
name: uptest-apim-subscription-example-rg
9798
spec:
9899
forProvider:
99100
location: West Europe

0 commit comments

Comments
 (0)