diff --git a/azurerm/data_source_api_management_api.go b/azurerm/data_source_api_management_api.go index a6483378101a8..25037b35565dd 100644 --- a/azurerm/data_source_api_management_api.go +++ b/azurerm/data_source_api_management_api.go @@ -75,15 +75,17 @@ func dataSourceApiManagementApi() *schema.Resource { "revision": { Type: schema.TypeInt, + Optional: true, + Default: 1, Computed: true, }, - "version": { + "api_version": { Type: schema.TypeString, Computed: true, }, - "version_set_id": { + "api_version_set_id": { Type: schema.TypeString, Computed: true, }, @@ -108,9 +110,9 @@ func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) er resGroup := d.Get("resource_group_name").(string) serviceName := d.Get("service_name").(string) name := d.Get("name").(string) + revision := int32(d.Get("revision").(int)) - //Currently we don't support revisions, so we use 1 as default - apiId := fmt.Sprintf("%s;rev=%d", name, 1) + apiId := fmt.Sprintf("%s;rev=%d", name, revision) resp, err := client.Get(ctx, resGroup, serviceName, apiId) @@ -133,8 +135,8 @@ func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) er d.Set("path", props.Path) d.Set("description", props.Description) d.Set("revision", props.APIRevision) - d.Set("version", props.APIVersion) - d.Set("version_set_id", props.APIVersionSetID) + d.Set("api_version", props.APIVersion) + d.Set("api_version_set_id", props.APIVersionSetID) d.Set("is_current", props.IsCurrent) d.Set("is_online", props.IsOnline) d.Set("protocols", props.Protocols) diff --git a/azurerm/data_source_api_management_api_test.go b/azurerm/data_source_api_management_api_test.go index d31f269af116f..2c8257adfad06 100644 --- a/azurerm/data_source_api_management_api_test.go +++ b/azurerm/data_source_api_management_api_test.go @@ -61,12 +61,12 @@ resource "azurerm_api_management" "test" { } resource "azurerm_api_management_api" "test" { - name = "acctestAMA-%d" - service_name = "${azurerm_api_management.test.name}" - path = "api1" + name = "acctestAMA-%d" + service_name = "${azurerm_api_management.test.name}" + path = "api1" - import { - content_value = "${file("testdata/api_management_api_swagger.json")}" + import { + content_value = "${file("testdata/api_management_api_swagger.json")}" content_format = "swagger-json" } @@ -75,7 +75,7 @@ resource "azurerm_api_management_api" "test" { data "azurerm_api_management_api" "test" { name = "${azurerm_api_management_api.test.name}" - service_name = "${azurerm_api_management.test.name}" + service_name = "${azurerm_api_management.test.name}" resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" } `, rInt, location, rInt, rInt) diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index 530d6bab05ca6..23a19e20b40ba 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -45,6 +45,18 @@ func resourceArmApiManagementApi() *schema.Resource { ValidateFunc: validate.ApiManagementApiPath, }, + "protocols": { + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.ProtocolHTTP), + string(apimanagement.ProtocolHTTPS), + }, false), + }, + Required: true, + }, + "api_id": { Type: schema.TypeString, Computed: true, @@ -80,8 +92,7 @@ func resourceArmApiManagementApi() *schema.Resource { string(apimanagement.WadlXML), string(apimanagement.Wsdl), string(apimanagement.WsdlLink), - }, true), - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, false), }, "wsdl_selector": { @@ -106,20 +117,6 @@ func resourceArmApiManagementApi() *schema.Resource { }, }, - "protocols": { - Type: schema.TypeList, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, - ValidateFunc: validation.StringInSlice([]string{ - string(apimanagement.ProtocolHTTP), - string(apimanagement.ProtocolHTTPS), - }, true), - }, - Optional: true, - Computed: true, // Azure API sets protocols to https by default - }, - "subscription_key_parameter_names": { Type: schema.TypeList, Optional: true, @@ -149,7 +146,8 @@ func resourceArmApiManagementApi() *schema.Resource { "revision": { Type: schema.TypeInt, - Computed: true, + Optional: true, + Default: 1, }, "version": { @@ -184,9 +182,9 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf resGroup := d.Get("resource_group_name").(string) serviceName := d.Get("service_name").(string) name := d.Get("name").(string) + revision := int32(d.Get("revision").(int)) - //Currently we don't support revisions, so we use 1 as default - apiId := fmt.Sprintf("%s;rev=%d", name, 1) + apiId := fmt.Sprintf("%s;rev=%d", name, revision) d.Set("api_id", apiId) var properties *apimanagement.APICreateOrUpdateProperties @@ -327,7 +325,6 @@ func expandApiManagementApiProperties(d *schema.ResourceData) *apimanagement.API path := d.Get("path").(string) serviceUrl := d.Get("service_url").(string) description := d.Get("description").(string) - soapPassThrough := d.Get("soap_pass_through").(bool) props := &apimanagement.APICreateOrUpdateProperties{ Description: &description, @@ -338,31 +335,43 @@ func expandApiManagementApiProperties(d *schema.ResourceData) *apimanagement.API SubscriptionKeyParameterNames: expandApiManagementApiSubscriptionKeyParamNames(d), } - if soapPassThrough { - props.APIType = apimanagement.APIType(apimanagement.SoapPassThrough) + if v, ok := d.GetOk("soap_pass_through"); ok { + soapPassThrough := v.(bool) + + if soapPassThrough { + props.APIType = apimanagement.APIType(apimanagement.SoapPassThrough) + } else { + props.APIType = apimanagement.APIType(apimanagement.SoapToRest) + } } return props } func expandApiManagementApiSubscriptionKeyParamNames(d *schema.ResourceData) *apimanagement.SubscriptionKeyParameterNamesContract { - var contract apimanagement.SubscriptionKeyParameterNamesContract + vs := d.Get("subscription_key_parameter_names").([]interface{}) - if v, ok := d.GetOk("subscription_key_parameter_names.0.header"); ok { - header := v.(string) - contract.Header = &header - } + if len(vs) > 0 { + v := vs[0].(map[string]interface{}) + contract := apimanagement.SubscriptionKeyParameterNamesContract{} - if v, ok := d.GetOk("subscription_key_parameter_names.0.query"); ok { - query := v.(string) - contract.Query = &query - } + query := v["query"].(string) + header := v["header"].(string) + + if query != "" { + contract.Query = utils.String(query) + } + + if header != "" { + contract.Header = utils.String(header) + } - if contract.Header == nil && contract.Query == nil { - return nil + if query != "" || header != "" { + return &contract + } } - return &contract + return nil } func expandApiManagementApiProtocols(d *schema.ResourceData) *[]apimanagement.Protocol { @@ -388,27 +397,25 @@ func expandApiManagementImportProperties(d *schema.ResourceData) *apimanagement. Path: &path, } - if v, ok := d.GetOk("import.0.content_format"); ok { - props.ContentFormat = apimanagement.ContentFormat(v.(string)) - } + importVs := d.Get("import").([]interface{}) + importV := importVs[0].(map[string]interface{}) - if v, ok := d.GetOk("import.0.content_value"); ok { - content_val := v.(string) - props.ContentValue = &content_val - } + props.ContentFormat = apimanagement.ContentFormat(importV["content_format"].(string)) - if _, selectorUsed := d.GetOk("import.0.wsdl_selector"); selectorUsed { + cVal := importV["content_value"].(string) + props.ContentValue = &cVal + + wsdlSelectorVs := importV["wsdl_selector"].([]interface{}) + + if len(wsdlSelectorVs) > 0 { + wsdlSelectorV := wsdlSelectorVs[0].(map[string]interface{}) props.WsdlSelector = &apimanagement.APICreateOrUpdatePropertiesWsdlSelector{} - if v, ok := d.GetOk("import.0.wsdl_selector.0.service_name"); ok { - serviceName := v.(string) - props.WsdlSelector.WsdlServiceName = &serviceName - } + wSvcName := wsdlSelectorV["service_name"].(string) + wEndpName := wsdlSelectorV["endpoint_name"].(string) - if v, ok := d.GetOk("import.0.wsdl_selector.0.endpoint_name"); ok { - endpointName := v.(string) - props.WsdlSelector.WsdlEndpointName = &endpointName - } + props.WsdlSelector.WsdlServiceName = &wSvcName + props.WsdlSelector.WsdlEndpointName = &wEndpName } return props diff --git a/azurerm/resource_arm_api_management_api_test.go b/azurerm/resource_arm_api_management_api_test.go index 98839a05d83ff..c52d4bbc83377 100644 --- a/azurerm/resource_arm_api_management_api_test.go +++ b/azurerm/resource_arm_api_management_api_test.go @@ -32,10 +32,7 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) { ImportStateVerify: true, // Ignore state that is only persisted in Terraform and not on Azure side ImportStateVerifyIgnore: []string{ - "import.#", - "import.0.content_format", - "import.0.content_value", - "import.0.wsdl_selector.#", + "import", }, }, }, @@ -64,12 +61,7 @@ func TestAccAzureRMApiManagementApi_complete(t *testing.T) { ImportStateVerify: true, // Ignore state that is only persisted in Terraform and not on Azure side ImportStateVerifyIgnore: []string{ - "import.#", - "import.0.content_format", - "import.0.content_value", - "import.0.wsdl_selector.#", - "import.0.wsdl_selector.0.service_name", - "import.0.wsdl_selector.0.endpoint_name", + "import", }, }, }, @@ -124,7 +116,7 @@ func testCheckAzureRMApiManagementApiExists(name string) resource.TestCheckFunc conn := testAccProvider.Meta().(*ArmClient).apiManagementApiClient ctx := testAccProvider.Meta().(*ArmClient).StopContext - apiId := fmt.Sprintf("%s;rev=%d", name, 1) + apiId := fmt.Sprintf("%s;rev=%s", name, rs.Primary.Attributes["revision"]) resp, err := conn.Get(ctx, resourceGroup, serviceName, apiId) if err != nil { if utils.ResponseWasNotFound(resp.Response) { @@ -159,11 +151,11 @@ resource "azurerm_api_management" "test" { } resource "azurerm_api_management_api" "test" { - name = "acctestAMA-%d" - service_name = "${azurerm_api_management.test.name}" - path = "api1" + name = "acctestAMA-%d" + service_name = "${azurerm_api_management.test.name}" + path = "api1" - import { + import { content_value = "${file("testdata/api_management_api_swagger.json")}" content_format = "swagger-json" } @@ -194,12 +186,12 @@ resource "azurerm_api_management" "test" { } resource "azurerm_api_management_api" "test" { - name = "acctestAMA-%d" - service_name = "${azurerm_api_management.test.name}" - path = "api1" + name = "acctestAMA-%d" + service_name = "${azurerm_api_management.test.name}" + path = "api1" - import { - content_value = "${file("testdata/api_management_api_wsdl.xml")}" + import { + content_value = "${file("testdata/api_management_api_wsdl.xml")}" content_format = "wsdl" wsdl_selector { @@ -208,14 +200,14 @@ resource "azurerm_api_management_api" "test" { } } - soap_pass_through = true + soap_pass_through = true - subscription_key_parameter_names { - header = "test1" - query = "test2" - } + subscription_key_parameter_names { + header = "test1" + query = "test2" + } - protocols = ["http", "https"] + protocols = ["http", "https"] resource_group_name = "${azurerm_resource_group.test.name}" } diff --git a/azurerm/testdata/api_management_api_wsdl.xml b/azurerm/testdata/api_management_api_wsdl.xml index 4bbf8a7d27740..f4afcba1c641e 100644 --- a/azurerm/testdata/api_management_api_wsdl.xml +++ b/azurerm/testdata/api_management_api_wsdl.xml @@ -70,7 +70,7 @@ - + @@ -79,10 +79,10 @@ - + - + diff --git a/website/docs/d/api_management_api.html.markdown b/website/docs/d/api_management_api.html.markdown index 92781e71bd29e..694234bcf5d8b 100644 --- a/website/docs/d/api_management_api.html.markdown +++ b/website/docs/d/api_management_api.html.markdown @@ -54,14 +54,14 @@ output "api_management_api_id" { * `version_set_id` - A resource identifier for the related ApiVersionSet. -* `is_current` - Indicates if API revision is current api revision. +* `is_current` - Indicates if the API revision is current api revision. -* `is_online` - Indicates if API revision is accessible via the gateway. +* `is_online` - Indicates if the API revision is accessible via the gateway. --- A `subscription_key_parameter_names` block exports the following: -* `header` - Subscription key header name. Default is `Ocp-Apim-Subscription-Key`. +* `header` - Subscription key header name. -* `query` - Subscription key query string parameter name. Default is `subscription-key`. +* `query` - Subscription key query string parameter name. diff --git a/website/docs/r/api_management_api.html.markdown b/website/docs/r/api_management_api.html.markdown index 91e05ab3edcbb..c35ab49b3d1bc 100644 --- a/website/docs/r/api_management_api.html.markdown +++ b/website/docs/r/api_management_api.html.markdown @@ -38,7 +38,6 @@ resource "azurerm_api_management_api" "test" { content_format = "swagger-link-json" content_value = "http://conferenceapi.azurewebsites.net/?format=json" } - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } ``` @@ -47,13 +46,11 @@ resource "azurerm_api_management_api" "test" { The following arguments are supported: -* `name` - (Required) The name of the API Management API. - -* `resource_group_name` - (Required) The Name of the Resource Group where the API Management API exists. +* `name` - (Required) The name of the API Management API. Changing this forces a new resource to be created. -* `location` - (Required) The Azure location where the API Management API exists. +* `resource_group_name` - (Required) The Name of the Resource Group where the API Management API exists. Changing this forces a new resource to be created. -* `service_name` - (Required) The Name of the API Management Service where the API Management API exists +* `service_name` - (Required) The Name of the API Management Service where the API Management API exists. Changing this forces a new resource to be created. * `path` - (Required) Relative URL uniquely identifying this API and all of its resource paths within the API Management service instance. It is appended to the API endpoint base URL specified during the service instance creation to form a public URL for this API. @@ -111,9 +108,9 @@ In addition to all arguments above, the following attributes are exported: * `version_set_id` - A resource identifier for the related ApiVersionSet. -* `is_current` - Indicates if API revision is current api revision. +* `is_current` - Indicates if the API revision is current api revision. -* `is_online` - Indicates if API revision is accessible via the gateway. +* `is_online` - Indicates if the API revision is accessible via the gateway. ## Import