Skip to content

Commit

Permalink
r/api_management: fixing bugs in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Mar 18, 2019
1 parent 47f2106 commit 1500308
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions azurerm/resource_arm_api_management_product_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func resourceArmApiManagementProductApi() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"api_id": azure.SchemaApiManagementChildName(),
"api_name": azure.SchemaApiManagementChildName(),

"product_id": azure.SchemaApiManagementChildName(),

Expand All @@ -37,27 +37,27 @@ func resourceArmApiManagementProductApiCreate(d *schema.ResourceData, meta inter

resourceGroup := d.Get("resource_group_name").(string)
serviceName := d.Get("api_management_name").(string)
apiId := d.Get("api_id").(string)
apiName := d.Get("api_name").(string)
productId := d.Get("product_id").(string)

if requireResourcesToBeImported {
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiId)
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiName)
if err != nil {
if !utils.ResponseWasNotFound(resp) {
return fmt.Errorf("Error checking for present of existing API %q / Product %q (API Management Service %q / Resource Group %q): %+v", apiId, productId, serviceName, resourceGroup, err)
return fmt.Errorf("Error checking for present of existing API %q / Product %q (API Management Service %q / Resource Group %q): %+v", apiName, productId, serviceName, resourceGroup, err)
}
}

if !utils.ResponseWasNotFound(resp) {
subscriptionId := meta.(*ArmClient).subscriptionId
resourceId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/apis/%s", subscriptionId, resourceGroup, serviceName, productId, apiId)
resourceId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/apis/%s", subscriptionId, resourceGroup, serviceName, productId, apiName)
return tf.ImportAsExistsError("azurerm_api_management_product_api", resourceId)
}
}

resp, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, productId, apiId)
resp, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, productId, apiName)
if err != nil {
return fmt.Errorf("Error adding API %q to Product %q (API Management Service %q / Resource Group %q): %+v", apiId, productId, serviceName, resourceGroup, err)
return fmt.Errorf("Error adding API %q to Product %q (API Management Service %q / Resource Group %q): %+v", apiName, productId, serviceName, resourceGroup, err)
}

// there's no Read so this is best-effort
Expand All @@ -77,20 +77,20 @@ func resourceArmApiManagementProductApiRead(d *schema.ResourceData, meta interfa
resourceGroup := id.ResourceGroup
serviceName := id.Path["service"]
productId := id.Path["products"]
apiId := id.Path["apis"]
apiName := id.Path["apis"]

resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiId)
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiName)
if err != nil {
if utils.ResponseWasNotFound(resp) {
log.Printf("[DEBUG] API %q was not found in Product %q (API Management Service %q / Resource Group %q) was not found - removing from state!", apiId, productId, serviceName, resourceGroup)
log.Printf("[DEBUG] API %q was not found in Product %q (API Management Service %q / Resource Group %q) was not found - removing from state!", apiName, productId, serviceName, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("Error retrieving API %q / Product %q (API Management Service %q / Resource Group %q): %+v", apiId, productId, serviceName, resourceGroup, err)
return fmt.Errorf("Error retrieving API %q / Product %q (API Management Service %q / Resource Group %q): %+v", apiName, productId, serviceName, resourceGroup, err)
}

d.Set("api_id", apiId)
d.Set("api_name", apiName)
d.Set("product_id", productId)
d.Set("resource_group_name", resourceGroup)
d.Set("api_management_name", serviceName)
Expand All @@ -109,11 +109,11 @@ func resourceArmApiManagementProductApiDelete(d *schema.ResourceData, meta inter
resourceGroup := id.ResourceGroup
serviceName := id.Path["service"]
productId := id.Path["products"]
apiId := id.Path["apis"]
apiName := id.Path["apis"]

if resp, err := client.Delete(ctx, resourceGroup, serviceName, productId, apiId); err != nil {
if resp, err := client.Delete(ctx, resourceGroup, serviceName, productId, apiName); err != nil {
if !utils.ResponseWasNotFound(resp) {
return fmt.Errorf("Error removing API %q from Product %q (API Management Service %q / Resource Group %q): %+v", apiId, productId, serviceName, resourceGroup, err)
return fmt.Errorf("Error removing API %q from Product %q (API Management Service %q / Resource Group %q): %+v", apiName, productId, serviceName, resourceGroup, err)
}
}

Expand Down
14 changes: 7 additions & 7 deletions azurerm/resource_arm_api_management_product_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func testCheckAzureRMAPIManagementProductApiDestroy(s *terraform.State) error {
continue
}

apiId := rs.Primary.Attributes["api_id"]
apiName := rs.Primary.Attributes["api_name"]
productId := rs.Primary.Attributes["product_id"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]
serviceName := rs.Primary.Attributes["api_management_name"]

ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiId)
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiName)
if err != nil {
if !utils.ResponseWasNotFound(resp) {
return err
Expand All @@ -96,17 +96,17 @@ func testCheckAzureRMAPIManagementProductApiExists(resourceName string) resource
return fmt.Errorf("Not found: %s", resourceName)
}

apiId := rs.Primary.Attributes["api_id"]
apiName := rs.Primary.Attributes["api_name"]
productId := rs.Primary.Attributes["product_id"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]
serviceName := rs.Primary.Attributes["api_management_name"]

client := testAccProvider.Meta().(*ArmClient).apiManagementProductApisClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiId)
resp, err := client.CheckEntityExists(ctx, resourceGroup, serviceName, productId, apiName)
if err != nil {
if utils.ResponseWasNotFound(resp) {
return fmt.Errorf("Bad: API %q / Product %q (API Management Service %q / Resource Group %q) does not exist", apiId, productId, serviceName, resourceGroup)
return fmt.Errorf("Bad: API %q / Product %q (API Management Service %q / Resource Group %q) does not exist", apiName, productId, serviceName, resourceGroup)
}
return fmt.Errorf("Bad: Get on apiManagementProductApisClient: %+v", err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ resource "azurerm_api_management_api" "test" {
resource "azurerm_api_management_product_api" "test" {
product_id = "${azurerm_api_management_product.test.product_id}"
api_id = "${azurerm_api_management_api.test.id}"
api_name = "${azurerm_api_management_api.test.name}"
api_management_name = "${azurerm_api_management.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
Expand All @@ -171,7 +171,7 @@ func testAccAzureRMAPIManagementProductApi_requiresImport(rInt int, location str
%s
resource "azurerm_api_management_product_api" "import" {
api_id = "${azurerm_api_management_product_api.test.api_id}"
api_name = "${azurerm_api_management_product_api.test.api_name}"
product_id = "${azurerm_api_management_product_api.test.product_id}"
api_management_name = "${azurerm_api_management_product_api.test.api_management_name}"
resource_group_name = "${azurerm_api_management_product_api.test.resource_group_name}"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/api_management_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data "azurerm_api_management_api" "test" {
name = "search-api"
api_management_name = "search-api-management"
resource_group_name = "search-service"
revision = 2
revision = "2"
}
output "api_management_api_id" {
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/api_management_product_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ data "azurerm_api_management_product" "test" {
resource_group_name = "${data.azurerm_api_management.example.resource_group_name}"
}
resource "azurerm_api_management_group_user" "example" {
api_id = "${data.azurerm_api_management_api.example.id}"
product_id = "${data.azurerm_api_management_product.example.name}"
resource "azurerm_api_management_product_api" "example" {
api_name = "${data.azurerm_api_management_api.example.name}"
product_id = "${data.azurerm_api_management_product.example.product_id}"
api_management_name = "${data.azurerm_api_management.example.name}"
resource_group_name = "${data.azurerm_api_management.example.resource_group_name}"
}
Expand All @@ -43,7 +43,7 @@ resource "azurerm_api_management_group_user" "example" {

The following arguments are supported:

* `api_id` - (Required) The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.
* `api_name` - (Required) The Name of the API Management API within the API Management Service. Changing this forces a new resource to be created.

* `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created.

Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/api_management_product_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ data "azurerm_api_management_group" "example" {
resource_group_name = "${data.azurerm_api_management.example.resource_group_name}"
}
resource "azurerm_api_management_group_user" "example" {
user_id = "${data.azurerm_api_management_user.example.id}"
resource "azurerm_api_management_product_group" "example" {
product_id = "${data.azurerm_api_management_user.example.id}"
group_name = "${data.azurerm_api_management_group.example.name}"
api_management_name = "${data.azurerm_api_management.example.name}"
resource_group_name = "${data.azurerm_api_management.example.resource_group_name}"
Expand All @@ -42,7 +42,7 @@ resource "azurerm_api_management_group_user" "example" {

The following arguments are supported:

* `user_id` - (Required) The ID of the API Management User which should be assigned to this API Management Group. Changing this forces a new resource to be created.
* `product_id` - (Required) The ID of the API Management Product within the API Management Service. Changing this forces a new resource to be created.

* `group_name` - (Required) The Name of the API Management Group within the API Management Service. Changing this forces a new resource to be created.

Expand Down

0 comments on commit 1500308

Please sign in to comment.