Skip to content

Commit

Permalink
azurerm_spring_cloud_api_portal - support for the `api_try_out_enab…
Browse files Browse the repository at this point in the history
…led` 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 <[email protected]>
  • Loading branch information
ms-henglu and katbyte authored Jan 31, 2024
1 parent 4eabde7 commit a9c4a72
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
29 changes: 25 additions & 4 deletions internal/services/springcloud/spring_cloud_api_portal_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/spring_cloud_api_portal.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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?
Expand Down

0 comments on commit a9c4a72

Please sign in to comment.