Skip to content

Commit

Permalink
Merge pull request #4993 from sam-cogan/master
Browse files Browse the repository at this point in the history
Add APIVersion and APIVersionSetID to import
  • Loading branch information
tombuildsstuff authored Dec 12, 2019
2 parents fd84c2e + d2cf89d commit 0f65de9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions azurerm/resource_arm_api_management_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ 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 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)
Expand Down Expand Up @@ -230,6 +236,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{})
Expand All @@ -244,6 +251,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)
}
Expand All @@ -253,13 +264,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`")
}

protocolsRaw := d.Get("protocols").(*schema.Set).List()
protocols := expandApiManagementApiProtocols(protocolsRaw)

Expand Down

0 comments on commit 0f65de9

Please sign in to comment.