From 92decd74e9eb573ccd64f1a7191b7d7a03bce250 Mon Sep 17 00:00:00 2001 From: Jared Dickson Date: Fri, 8 Nov 2019 11:53:19 -0500 Subject: [PATCH] =?UTF-8?q?`azurerm=5Fapi=5Fmanagement=5Fapi`=20-=20the=20?= =?UTF-8?q?`version`=20and=20`version=5Fset=5Fi=E2=80=A6=20(#4592)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should fix #4297 --- azurerm/resource_arm_api_management_api.go | 14 +++++ .../resource_arm_api_management_api_test.go | 53 +++++++++++++++++++ .../docs/r/api_management_api.html.markdown | 6 +++ 3 files changed, 73 insertions(+) diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/resource_arm_api_management_api.go index aca20a4f1400..07ae51182938 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/resource_arm_api_management_api.go @@ -179,11 +179,13 @@ func resourceArmApiManagementApi() *schema.Resource { "version": { Type: schema.TypeString, Computed: true, + Optional: true, }, "version_set_id": { Type: schema.TypeString, Computed: true, + Optional: true, }, }, } @@ -251,6 +253,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) @@ -274,9 +283,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 05d73f2c5514..edc00e324a33 100644 --- a/website/docs/r/api_management_api.html.markdown +++ b/website/docs/r/api_management_api.html.markdown @@ -75,6 +75,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: