Skip to content

Commit

Permalink
Fixed and made changes according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
torresdal committed Oct 25, 2018
1 parent 815ce6e commit e30c1c9
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 103 deletions.
14 changes: 8 additions & 6 deletions azurerm/data_source_api_management_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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)

Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions azurerm/data_source_api_management_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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)
Expand Down
107 changes: 57 additions & 50 deletions azurerm/resource_arm_api_management_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,8 +92,7 @@ func resourceArmApiManagementApi() *schema.Resource {
string(apimanagement.WadlXML),
string(apimanagement.Wsdl),
string(apimanagement.WsdlLink),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
}, false),
},

"wsdl_selector": {
Expand All @@ -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,
Expand Down Expand Up @@ -149,7 +146,8 @@ func resourceArmApiManagementApi() *schema.Resource {

"revision": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Default: 1,
},

"version": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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
Expand Down
44 changes: 18 additions & 26 deletions azurerm/resource_arm_api_management_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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}"
}
Expand Down
6 changes: 3 additions & 3 deletions azurerm/testdata/api_management_api_wsdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</wsdl:binding>
<wsdl:service name="Calculator">
<wsdl:port name="CalculatorHttpsSoap11Endpoint" binding="ns:CalculatorSoap11Binding">
<soap:address location="https://156.56.179.164:9443/services/Calculator.CalculatorHttpsSoap11Endpoint/" />
<soap:address location="https://acceptancetests.terraform.io/services/Calculator.CalculatorHttpsSoap11Endpoint/" />
</wsdl:port>
<wsdl:port name="CalculatorHttpSoap11Endpoint" binding="ns:CalculatorSoap11Binding">
<soap:address location="http://156.56.179.164:9763/services/Calculator.CalculatorHttpSoap11Endpoint/" />
Expand All @@ -79,10 +79,10 @@
<soap12:address location="http://156.56.179.164:9763/services/Calculator.CalculatorHttpSoap12Endpoint/" />
</wsdl:port>
<wsdl:port name="CalculatorHttpsSoap12Endpoint" binding="ns:CalculatorSoap12Binding">
<soap12:address location="https://156.56.179.164:9443/services/Calculator.CalculatorHttpsSoap12Endpoint/" />
<soap12:address location="https://acceptancetests.terraform.io/services/Calculator.CalculatorHttpsSoap12Endpoint/" />
</wsdl:port>
<wsdl:port name="CalculatorHttpsEndpoint" binding="ns:CalculatorHttpBinding">
<http:address location="https://156.56.179.164:9443/services/Calculator.CalculatorHttpsEndpoint/" />
<http:address location="https://acceptancetests.terraform.io/services/Calculator.CalculatorHttpsEndpoint/" />
</wsdl:port>
<wsdl:port name="CalculatorHttpEndpoint" binding="ns:CalculatorHttpBinding">
<http:address location="http://156.56.179.164:9763/services/Calculator.CalculatorHttpEndpoint/" />
Expand Down
8 changes: 4 additions & 4 deletions website/docs/d/api_management_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading

0 comments on commit e30c1c9

Please sign in to comment.