Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_api Deprecate soap_pass_through in favour of api_type #17812

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 53 additions & 18 deletions internal/services/apimanagement/api_management_api_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
Expand All @@ -20,7 +21,7 @@ import (
)

func resourceApiManagementApi() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceApiManagementApiCreateUpdate,
Read: resourceApiManagementApiRead,
Update: resourceApiManagementApiCreateUpdate,
Expand Down Expand Up @@ -67,6 +68,8 @@ func resourceApiManagementApi() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
string(apimanagement.ProtocolHTTP),
string(apimanagement.ProtocolHTTPS),
string(apimanagement.ProtocolWs),
string(apimanagement.ProtocolWss),
}, false),
},
},
Expand All @@ -85,6 +88,18 @@ func resourceApiManagementApi() *pluginsdk.Resource {
},

// Optional
"api_type": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
string(apimanagement.APITypeGraphql),
string(apimanagement.APITypeHTTP),
string(apimanagement.APITypeSoap),
string(apimanagement.APITypeWebsocket),
}, false),
},

"description": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -176,12 +191,6 @@ func resourceApiManagementApi() *pluginsdk.Resource {
Default: true,
},

"soap_pass_through": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"source_api_id": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -264,6 +273,20 @@ func resourceApiManagementApi() *pluginsdk.Resource {
},
},
}

if !features.FourPointOhBeta() {
resource.Schema["api_type"].ConflictsWith = []string{"soap_pass_through"}

resource.Schema["soap_pass_through"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Deprecated: "`soap_pass_through` will be removed in favour of the property `api_type` in version 4.0 of the AzureRM Provider",
ConflictsWith: []string{"api_type"},
}
}

return resource
}

func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -305,17 +328,22 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf
}
}

var apiType apimanagement.APIType
var soapApiType apimanagement.SoapAPIType

soapPassThrough := d.Get("soap_pass_through").(bool)
if soapPassThrough {
apiType = apimanagement.APITypeSoap
soapApiType = apimanagement.SoapAPITypeSoapPassThrough
} else {
apiType = apimanagement.APITypeHTTP
soapApiType = apimanagement.SoapAPITypeSoapToRest
apiType := apimanagement.APITypeHTTP
if v, ok := d.GetOk("api_type"); ok {
apiType = apimanagement.APIType(v.(string))
}
if !features.FourPointOhBeta() {
if d.Get("soap_pass_through").(bool) {
apiType = apimanagement.APITypeSoap
}
}

soapApiType := map[apimanagement.APIType]apimanagement.SoapAPIType{
apimanagement.APITypeGraphql: apimanagement.SoapAPITypeGraphQL,
apimanagement.APITypeHTTP: apimanagement.SoapAPITypeSoapToRest,
apimanagement.APITypeSoap: apimanagement.SoapAPITypeSoapPassThrough,
apimanagement.APITypeWebsocket: apimanagement.SoapAPITypeWebSocket,
}[apiType]

// If import is used, we need to send properties to Azure API in two operations.
// First we execute import and then updated the other props.
Expand Down Expand Up @@ -460,14 +488,21 @@ func resourceApiManagementApiRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("resource_group_name", id.ResourceGroup)

if props := resp.APIContractProperties; props != nil {
apiType := string(props.APIType)
if len(apiType) == 0 {
apiType = string(apimanagement.APITypeHTTP)
}
d.Set("api_type", apiType)
d.Set("description", props.Description)
d.Set("display_name", props.DisplayName)
d.Set("is_current", props.IsCurrent)
d.Set("is_online", props.IsOnline)
d.Set("path", props.Path)
d.Set("service_url", props.ServiceURL)
d.Set("revision", props.APIRevision)
d.Set("soap_pass_through", string(props.APIType) == string(apimanagement.SoapAPITypeSoapPassThrough))
if !features.FourPointOhBeta() {
d.Set("soap_pass_through", apiType == string(apimanagement.SoapAPITypeSoapPassThrough))
}
d.Set("subscription_required", props.SubscriptionRequired)
d.Set("version", props.APIVersion)
d.Set("version_set_id", props.APIVersionSetID)
Expand Down
Loading