-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
767b9a6
commit 72e2f15
Showing
4 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
subcategory: "APIG" | ||
--- | ||
|
||
# opentelekomcloud_apigw_throttling_policy_associate_v2 | ||
|
||
This API is used to bind a request throttling policy to an API that has been published in an environment within OpenTelekomCloud. | ||
You can bind different request throttling policies to an API in different environments, | ||
but can bind only one request throttling policy to the API in each environment. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "gateway_id" {} | ||
variable "policy_id" {} | ||
variable "publish_ids" { | ||
type = list(string) | ||
} | ||
resource "opentelekomcloud_apigw_throttling_policy_associate_v2" "tpa" { | ||
gateway_id = var.gateway_id | ||
policy_id = var.policy_id | ||
publish_ids = var.publish_ids | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
* `gateway_id` - (Required, String, ForceNew) Specifies the ID of the dedicated gateway to which the APIs and the | ||
throttling policy belongs. | ||
Changing this will create a new resource. | ||
|
||
* `policy_id` - (Required, String, ForceNew) Specifies the ID of the throttling policy. | ||
Changing this will create a new resource. | ||
|
||
* `publish_ids` - (Required, List) Specifies the publishing IDs corresponding to the APIs bound by the throttling policy. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - Resource ID. The format is `<instance_id>/<policy_id>`. | ||
|
||
* `region` - Specifies the region where the dedicated instance and the throttling policy are located. | ||
|
||
## Import | ||
|
||
Resources can be imported using their `policy_id` and the APIGW dedicated gateway ID to which the policy | ||
belongs, separated by a slash, e.g. | ||
|
||
```shell | ||
$ terraform import opentelekomcloud_apigw_throttling_policy_associate_v2.tpa <instance_id>/<policy_id> | ||
``` |
155 changes: 155 additions & 0 deletions
155
...loud/acceptance/apigw/resource_opentelekomcloud_apigw_throttling_policy_associate_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
throttlingpolicy "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/tr_policy" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env" | ||
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg" | ||
) | ||
|
||
const resourceApigwAssociateName = "opentelekomcloud_apigw_throttling_policy_associate_v2.associate" | ||
|
||
func getAssociateFunc(conf *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
c, err := conf.APIGWV2Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating OpenTelekomCloud APIG v2 client: %s", err) | ||
} | ||
opt := throttlingpolicy.ListBoundOpts{ | ||
GatewayID: state.Primary.Attributes["gateway_id"], | ||
ThrottleID: state.Primary.Attributes["policy_id"], | ||
} | ||
return throttlingpolicy.ListAPIBoundPolicy(c, opt) | ||
} | ||
|
||
func TestAccThrottlingPolicyAssociate_basic(t *testing.T) { | ||
var apiDetails []throttlingpolicy.ApiThrottle | ||
name := fmt.Sprintf("apigw_acc_thpa%s", acctest.RandString(10)) | ||
rc := common.InitResourceCheck( | ||
resourceApigwAssociateName, | ||
&apiDetails, | ||
getAssociateFunc, | ||
) | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
common.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccThrottlingPolicyAssociateV2_basic(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(resourceApigwAssociateName, "gateway_id"), | ||
resource.TestCheckResourceAttrSet(resourceApigwAssociateName, "policy_id"), | ||
resource.TestCheckResourceAttr(resourceApigwAssociateName, "publish_ids.#", "1"), | ||
), | ||
}, { | ||
Config: testAccThrottlingPolicyAssociateV2_update(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(resourceApigwAssociateName, "gateway_id"), | ||
resource.TestCheckResourceAttrSet(resourceApigwAssociateName, "policy_id"), | ||
resource.TestCheckResourceAttr(resourceApigwAssociateName, "publish_ids.#", "1"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceApigwAssociateName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccThrottlingPolicyAssociateV2_basic(name string) string { | ||
relatedConfig := testAccApigwApi_basic(testAccApigwApi_base(name), name) | ||
return fmt.Sprintf(` | ||
%s | ||
resource "opentelekomcloud_apigw_environment_v2" "env_two" { | ||
name = "second_env_%[2]s" | ||
instance_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
description = "test description" | ||
} | ||
resource "opentelekomcloud_apigw_api_publishment_v2" "pub_one" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
environment_id = opentelekomcloud_apigw_environment_v2.env.id | ||
api_id = opentelekomcloud_apigw_api_v2.api.id | ||
} | ||
resource "opentelekomcloud_apigw_api_publishment_v2" "pub_two" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
environment_id = opentelekomcloud_apigw_environment_v2.env_two.id | ||
api_id = opentelekomcloud_apigw_api_v2.api.id | ||
} | ||
resource "opentelekomcloud_apigw_throttling_policy_v2" "policy" { | ||
instance_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
name = "policy_%[2]s" | ||
type = "API-based" | ||
period = 15000 | ||
period_unit = "SECOND" | ||
max_api_requests = 100 | ||
} | ||
resource "opentelekomcloud_apigw_throttling_policy_associate_v2" "associate" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
policy_id = opentelekomcloud_apigw_throttling_policy_v2.policy.id | ||
publish_ids = [ | ||
opentelekomcloud_apigw_api_publishment_v2.pub_one.publish_id | ||
] | ||
} | ||
`, relatedConfig, name) | ||
} | ||
|
||
func testAccThrottlingPolicyAssociateV2_update(name string) string { | ||
relatedConfig := testAccApigwApi_basic(testAccApigwApi_base(name), name) | ||
return fmt.Sprintf(` | ||
%s | ||
resource "opentelekomcloud_apigw_environment_v2" "env_two" { | ||
name = "second_env_%[2]s" | ||
instance_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
description = "test description" | ||
} | ||
resource "opentelekomcloud_apigw_api_publishment_v2" "pub_one" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
environment_id = opentelekomcloud_apigw_environment_v2.env.id | ||
api_id = opentelekomcloud_apigw_api_v2.api.id | ||
} | ||
resource "opentelekomcloud_apigw_api_publishment_v2" "pub_two" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
environment_id = opentelekomcloud_apigw_environment_v2.env_two.id | ||
api_id = opentelekomcloud_apigw_api_v2.api.id | ||
} | ||
resource "opentelekomcloud_apigw_throttling_policy_v2" "policy" { | ||
instance_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
name = "policy_%[2]s" | ||
type = "API-based" | ||
period = 15000 | ||
period_unit = "SECOND" | ||
max_api_requests = 100 | ||
} | ||
resource "opentelekomcloud_apigw_throttling_policy_associate_v2" "associate" { | ||
gateway_id = opentelekomcloud_apigw_gateway_v2.gateway.id | ||
policy_id = opentelekomcloud_apigw_throttling_policy_v2.policy.id | ||
publish_ids = [ | ||
opentelekomcloud_apigw_api_publishment_v2.pub_two.publish_id | ||
] | ||
} | ||
`, relatedConfig, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.