From c77d55df78efe2e164a193bb4484f225e700c6ad Mon Sep 17 00:00:00 2001 From: Sam Cogan Date: Tue, 26 Nov 2019 20:26:22 +0000 Subject: [PATCH 1/3] Add APIVersion and APIVersionSetID to import --- azurerm/resource_arm_api_management_api.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index 07ae51182938..179f9043b017 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -202,6 +202,8 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf revision := d.Get("revision").(string) path := d.Get("path").(string) apiId := fmt.Sprintf("%s;rev=%s", name, revision) + version := d.Get("version").(string) + versionSetId := d.Get("version_set_id").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, serviceName, apiId) @@ -230,6 +232,7 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf ContentFormat: apimanagement.ContentFormat(contentFormat), ContentValue: utils.String(contentValue), Path: utils.String(path), + APIVersion: utils.String(version), }, } wsdlSelectorVs := importV["wsdl_selector"].([]interface{}) @@ -244,6 +247,10 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf } } + if versionSetId != "" { + apiParams.APICreateOrUpdateProperties.APIVersionSetID = utils.String(versionSetId) + } + if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, apiId, apiParams, ""); err != nil { return fmt.Errorf("Error creating/updating API Management API %q (Resource Group %q): %+v", name, resourceGroup, err) } @@ -253,9 +260,6 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf displayName := d.Get("display_name").(string) serviceUrl := d.Get("service_url").(string) - version := d.Get("version").(string) - versionSetId := d.Get("version_set_id").(string) - if version != "" && versionSetId == "" { return fmt.Errorf("Error setting `version` without the required `version_set_id`") } From 1dbec63ccb1cda74f56baedf4c60b2d3192288c7 Mon Sep 17 00:00:00 2001 From: Sam Cogan Date: Wed, 27 Nov 2019 09:55:31 +0000 Subject: [PATCH 2/3] Move validation for versionSetID earlier --- azurerm/resource_arm_api_management_api.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index 179f9043b017..8afda037ce23 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -204,6 +204,10 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf apiId := fmt.Sprintf("%s;rev=%s", name, revision) version := d.Get("version").(string) versionSetId := d.Get("version_set_id").(string) + + if version != "" && versionSetId == "" { + return fmt.Errorf("Error setting `version` without the required `version_set_id`") + } if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, serviceName, apiId) @@ -260,9 +264,6 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf displayName := d.Get("display_name").(string) serviceUrl := d.Get("service_url").(string) - if version != "" && versionSetId == "" { - return fmt.Errorf("Error setting `version` without the required `version_set_id`") - } protocolsRaw := d.Get("protocols").(*schema.Set).List() protocols := expandApiManagementApiProtocols(protocolsRaw) From d2cf89dbf1addac3c6d05b00da15681734f9b43d Mon Sep 17 00:00:00 2001 From: Sam Cogan Date: Wed, 27 Nov 2019 11:57:21 +0000 Subject: [PATCH 3/3] Fix formatting of file --- azurerm/resource_arm_api_management_api.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index 8afda037ce23..ee9737ca7fd1 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -204,7 +204,7 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf apiId := fmt.Sprintf("%s;rev=%s", name, revision) version := d.Get("version").(string) versionSetId := d.Get("version_set_id").(string) - + if version != "" && versionSetId == "" { return fmt.Errorf("Error setting `version` without the required `version_set_id`") } @@ -264,7 +264,6 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf displayName := d.Get("display_name").(string) serviceUrl := d.Get("service_url").(string) - protocolsRaw := d.Get("protocols").(*schema.Set).List() protocols := expandApiManagementApiProtocols(protocolsRaw)