Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_api - the version and version_set_id properties can now be set #4592

Merged
merged 12 commits into from
Nov 8, 2019
14 changes: 14 additions & 0 deletions azurerm/resource_arm_api_management_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ func resourceArmApiManagementApi() *schema.Resource {
"version": {
Type: schema.TypeString,
Computed: true,
Optional: true,
kraihn marked this conversation as resolved.
Show resolved Hide resolved
},

"version_set_id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
},
}
Expand Down Expand Up @@ -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)
kraihn marked this conversation as resolved.
Show resolved Hide resolved

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 All @@ -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 != "" {
kraihn marked this conversation as resolved.
Show resolved Hide resolved
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)
}
Expand Down
53 changes: 53 additions & 0 deletions azurerm/resource_arm_api_management_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/api_management_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down