From a9c4a721fb87ec8a529b55b26c1305ee3998da28 Mon Sep 17 00:00:00 2001 From: Heng Lu <79895375+ms-henglu@users.noreply.github.com> Date: Thu, 1 Feb 2024 03:48:51 +0800 Subject: [PATCH] `azurerm_spring_cloud_api_portal` - support for the `api_try_out_enabled` property (#24696) * `azurerm_spring_cloud_api_portal` - support for the `api_try_out_enabled` property * Update website/docs/r/spring_cloud_api_portal.html.markdown --------- Co-authored-by: kt --- .../spring_cloud_api_portal_resource.go | 29 ++++++++++++++++--- .../spring_cloud_api_portal_resource_test.go | 1 + .../r/spring_cloud_api_portal.html.markdown | 3 ++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/internal/services/springcloud/spring_cloud_api_portal_resource.go b/internal/services/springcloud/spring_cloud_api_portal_resource.go index a41948cbe8cf..cd81c2b7b991 100644 --- a/internal/services/springcloud/spring_cloud_api_portal_resource.go +++ b/internal/services/springcloud/spring_cloud_api_portal_resource.go @@ -25,6 +25,7 @@ type SpringCloudAPIPortalModel struct { HttpsOnlyEnabled bool `tfschema:"https_only_enabled"` InstanceCount int `tfschema:"instance_count"` PublicNetworkAccessEnabled bool `tfschema:"public_network_access_enabled"` + ApiTryOutEnabled bool `tfschema:"api_try_out_enabled"` Sso []ApiPortalSsoModel `tfschema:"sso"` Url string `tfschema:"url"` } @@ -71,6 +72,11 @@ func (s SpringCloudAPIPortalResource) Arguments() map[string]*pluginsdk.Schema { ValidateFunc: commonids.ValidateSpringCloudServiceID, }, + "api_try_out_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + "gateway_ids": { Type: pluginsdk.TypeSet, Optional: true, @@ -184,12 +190,18 @@ func (s SpringCloudAPIPortalResource) Create() sdk.ResourceFunc { return fmt.Errorf("invalid `sku` for %s", springId) } + apiTryOutEnabledState := appplatform.ApiPortalApiTryOutEnabledStateDisabled + if model.ApiTryOutEnabled { + apiTryOutEnabledState = appplatform.ApiPortalApiTryOutEnabledStateEnabled + } + apiPortalResource := appplatform.ApiPortalResource{ Properties: &appplatform.ApiPortalProperties{ - GatewayIds: pointer.To(model.GatewayIds), - HTTPSOnly: pointer.To(model.HttpsOnlyEnabled), - Public: pointer.To(model.PublicNetworkAccessEnabled), - SsoProperties: expandAPIPortalSsoProperties(model.Sso), + GatewayIds: pointer.To(model.GatewayIds), + HTTPSOnly: pointer.To(model.HttpsOnlyEnabled), + Public: pointer.To(model.PublicNetworkAccessEnabled), + SsoProperties: expandAPIPortalSsoProperties(model.Sso), + ApiTryOutEnabledState: pointer.To(apiTryOutEnabledState), }, Sku: &appplatform.Sku{ Name: service.Model.Sku.Name, @@ -262,6 +274,14 @@ func (s SpringCloudAPIPortalResource) Update() sdk.ResourceFunc { sku.Capacity = pointer.To(int64(model.InstanceCount)) } + if metadata.ResourceData.HasChange("api_try_out_enabled") { + apiTryOutEnabledState := appplatform.ApiPortalApiTryOutEnabledStateDisabled + if model.ApiTryOutEnabled { + apiTryOutEnabledState = appplatform.ApiPortalApiTryOutEnabledStateEnabled + } + properties.ApiTryOutEnabledState = pointer.To(apiTryOutEnabledState) + } + apiPortalResource := appplatform.ApiPortalResource{ Properties: properties, Sku: sku, @@ -312,6 +332,7 @@ func (s SpringCloudAPIPortalResource) Read() sdk.ResourceFunc { state.HttpsOnlyEnabled = pointer.From(props.HTTPSOnly) state.PublicNetworkAccessEnabled = pointer.From(props.Public) state.Sso = flattenAPIPortalSsoProperties(props.SsoProperties, model.Sso) + state.ApiTryOutEnabled = props.ApiTryOutEnabledState != nil && *props.ApiTryOutEnabledState == appplatform.ApiPortalApiTryOutEnabledStateEnabled } if sku := resp.Model.Sku; sku != nil { diff --git a/internal/services/springcloud/spring_cloud_api_portal_resource_test.go b/internal/services/springcloud/spring_cloud_api_portal_resource_test.go index 0552e645a438..d0a5c2f1860f 100644 --- a/internal/services/springcloud/spring_cloud_api_portal_resource_test.go +++ b/internal/services/springcloud/spring_cloud_api_portal_resource_test.go @@ -172,6 +172,7 @@ resource "azurerm_spring_cloud_api_portal" "test" { https_only_enabled = false public_network_access_enabled = false instance_count = 1 + api_try_out_enabled = true sso { client_id = "%s" diff --git a/website/docs/r/spring_cloud_api_portal.html.markdown b/website/docs/r/spring_cloud_api_portal.html.markdown index 048182b3293b..d1df29f017d2 100644 --- a/website/docs/r/spring_cloud_api_portal.html.markdown +++ b/website/docs/r/spring_cloud_api_portal.html.markdown @@ -43,6 +43,7 @@ resource "azurerm_spring_cloud_api_portal" "example" { https_only_enabled = false public_network_access_enabled = true instance_count = 1 + api_try_out_enabled = true sso { client_id = "test" client_secret = "secret" @@ -62,6 +63,8 @@ The following arguments are supported: --- +* `api_try_out_enabled` - (Optional) Specifies whether the API try-out feature is enabled. When enabled, users can try out the API by sending requests and viewing responses in API portal. + * `gateway_ids` - (Optional) Specifies a list of Spring Cloud Gateway. * `https_only_enabled` - (Optional) is only https is allowed?