diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index 4f2c7efa6699..f84fde09ca23 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -171,11 +171,13 @@ func resourceArmApiManagementApi() *schema.Resource { "version": { Type: schema.TypeString, Computed: true, + Optional: true, }, "version_set_id": { Type: schema.TypeString, Computed: true, + Optional: true, }, }, } @@ -243,6 +245,13 @@ 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) @@ -266,9 +275,14 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf Protocols: protocols, ServiceURL: utils.String(serviceUrl), SubscriptionKeyParameterNames: subscriptionKeyParameterNames, + APIVersion: utils.String(version), }, } + if versionSetId != "" { + params.APICreateOrUpdateProperties.APIVersionSetID = utils.String(versionSetId) + } + if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, apiId, params, ""); err != nil { return fmt.Errorf("Error creating/updating API %q / Revision %q (API Management Service %q / Resource Group %q): %+v", name, revision, serviceName, resourceGroup, err) } diff --git a/azurerm/resource_arm_api_management_api_test.go b/azurerm/resource_arm_api_management_api_test.go index 28935295da31..a1097c61503f 100644 --- a/azurerm/resource_arm_api_management_api_test.go +++ b/azurerm/resource_arm_api_management_api_test.go @@ -94,6 +94,32 @@ func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { }) } +func TestAccAzureRMApiManagementApi_version(t *testing.T) { + resourceName := "azurerm_api_management_api.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementApiDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementApi_versionSet(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementApiExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "version", "v1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMApiManagementApi_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -495,6 +521,33 @@ resource "azurerm_api_management_api" "test" { `, template, rInt) } +func testAccAzureRMApiManagementApi_versionSet(rInt int, location string) string { + template := testAccAzureRMApiManagementApi_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_api_version_set" "test" { + name = "acctestAMAVS-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = "${azurerm_api_management.test.name}" + display_name = "Butter Parser" + versioning_scheme = "Segment" +} + +resource "azurerm_api_management_api" "test" { + name = "acctestapi-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = "${azurerm_api_management.test.name}" + display_name = "api1" + path = "api1" + protocols = ["https"] + revision = "1" + version = "v1" + version_set_id = "${azurerm_api_management_api_version_set.test.id}" +} +`, template, rInt, rInt) +} + func testAccAzureRMApiManagementApi_template(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { diff --git a/website/docs/r/api_management_api.html.markdown b/website/docs/r/api_management_api.html.markdown index 68f045a1b2f6..1180c17f75cf 100644 --- a/website/docs/r/api_management_api.html.markdown +++ b/website/docs/r/api_management_api.html.markdown @@ -74,6 +74,12 @@ The following arguments are supported: * `subscription_key_parameter_names` - (Optional) A `subscription_key_parameter_names` block as documented below. +* `version` - (Optional) The Version number of this API, if this API is versioned. + +* `version_set_id` - (Optional) The ID of the Version Set which this API is associated with. + +-> **NOTE:** When `version` is set, `version_set_id` must also be specified + --- A `import` block supports the following: