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

[APIGW] New features resources #2755

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/data-sources/apigw_gateway_features_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
subcategory: "APIGW"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_apigw_gateway_features_v2"
sidebar_current: "docs-opentelekomcloud-datasource-apigw-gateway-features-v2"
description: |-
Get the all APIGW gateway features from OpenTelekomCloud
---

Up-to-date reference of API arguments for API Gateway environment variable service you can get at
[documentation portal](https://docs.otc.t-systems.com/api-gateway/api-ref/dedicated_gateway_apis_v2/gateway_feature_management/querying_gateway_features.html)

# opentelekomcloud_apigw_gateway_features_v2

Use this data source to get the list of the features under the APIGW gateway within OpenTelekomCloud.

## Example Usage

```hcl
variable gateway_id {}

data "opentelekomcloud_apigw_gateway_features_v2" "ft" {
gateway_id = var.gateway_id
}
```

## Argument Reference

The following arguments are supported:

* `gateway_id` - (Required, String) Specified the ID of the dedicated gateway to which the features belong.

* `name` - (Optional, String) Specified the name of the feature.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `region` - The region in which to query the data source.

* `features` - All instance features that match the filter parameters.
The [features](#instance_features) structure is documented below.

<a name="instance_features"></a>
The `features` block supports:

* `id` - The ID of the feature.

* `name` - The name of the feature.

* `enabled` - Whether the feature is enabled.

* `config` - The detailed configuration of the instance feature.

* `updated_at` - The latest update time of the feature, in RFC3339 format.
70 changes: 70 additions & 0 deletions docs/resources/apigw_gateway_feature_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
subcategory: "APIGW"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_apigw_gateway_feature_v2"
sidebar_current: "docs-opentelekomcloud-resource-apigw-gateway-feature-v2"
description: |-
Manages a APIGW gateway feature resource within OpenTelekomCloud.
---

Up-to-date reference of API arguments for API Gateway environment variable service you can get at
[documentation portal](https://docs.otc.t-systems.com/api-gateway/api-ref/dedicated_gateway_apis_v2/gateway_feature_management/configuring_a_feature_for_a_gateway.html)

# opentelekomcloud_apigw_gateway_feature_v2

Manages an APIGW gateway feature resource within OpenTelekomCloud.

-> For various types of feature parameter configurations, please refer to the
[documentation](https://docs.otc.t-systems.com/api-gateway/api-ref/appendix/supported_features.html#apig-api-20200402).

## Example Usage

```hcl
variable "gateway_id" {}

resource "opentelekomcloud_apigw_gateway_feature_v2" "feat" {
gateway_id = var.gateway_id
name = "ratelimit"
enabled = true

config = jsonencode({
api_limits = 300
})
}
```

## Argument Reference

The following arguments are supported:

* `gateway_id` - (Required, String, ForceNew) Specified the ID of the dedicated gateway to which the feature belongs.
Changing this creates a new resource.

* `name` - (Required, String, ForceNew) Specified the name of the feature.
Changing this creates a new resource.

* `enabled` - (Optional, Bool) Specified whether to enable the feature. Default value is `false`.

* `config` - (Optional, String) Specified the detailed configuration of the feature.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID. The value is the feature name.

* `region` - The region in which to create the resource.

## Timeouts

This resource provides the following timeouts configuration options:

* `create` - Default is 5 minutes.

## Import

The resource can be imported using `gateway_id` and `name`, separated by a slash (/), e.g.

```bash
$ terraform import opentelekomcloud_apigw_gateway_feature_v2.feat <gateway_id>/<name>
```
53 changes: 53 additions & 0 deletions docs/resources/apigw_gateway_routes_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
subcategory: "APIGW"
layout: "opentelekomcloud"
page_title: "OpenTelekomCloud: opentelekomcloud_apigw_gateway_routes_v2"
sidebar_current: "docs-opentelekomcloud-resource-apigw-gateway-routes-v2"
description: |-
Manages a APIGW gateway routes resource within OpenTelekomCloud.
---

Up-to-date reference of API arguments for API Gateway environment variable service you can get at
[documentation portal](https://docs.otc.t-systems.com/api-gateway/api-ref/dedicated_gateway_apis_v2/gateway_feature_management/configuring_a_feature_for_a_gateway.html)

# opentelekomcloud_apigw_gateway_routes_v2

Manages a APIGW gateway routes resource within OpenTelekomCloud.

## Example Usage

```hcl
variable "gateway_id" {}

resource "opentelekomcloud_apigw_gateway_routes_v2" "rt" {
gateway_id = var.gateway_id
nexthops = ["172.16.3.0/24", "172.16.7.0/24"]
}
```

## Argument Reference

The following arguments are supported:

* `gateway_id` - (Required, String, ForceNew) Specifies the ID of the dedicated gateway to which the routes belong.
Changing this will create a new resource.

* `nexthops` - (Required, List) Specifies the configuration of the next-hop routes.

-> The network segment of the next hop cannot overlap with the network segment of the APIGW gateway.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID (gateway ID).

* `region` - The region where the dedicated gateway and routes are located.

## Import

Routes can be imported using their related dedicated instance ID (`gateway_id`), e.g.

```bash
$ terraform import opentelekomcloud_apigw_gateway_routes_v2.rt 628001b3c5eg6d3e91a8da530f46427y
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package acceptance

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
)

func TestAccDataSourceInstanceFeatures_basic(t *testing.T) {
var (
rName = "data.opentelekomcloud_apigw_gateway_features_v2.test"
dc = common.InitDataSourceCheck(rName)

byName = "data.opentelekomcloud_apigw_gateway_features_v2.filter_by_name"
dcByName = common.InitDataSourceCheck(byName)

byNotFoundName = "data.opentelekomcloud_apigw_gateway_features_v2.filter_by_not_found_name"
dcByNotFoundName = common.InitDataSourceCheck(byNotFoundName)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
common.TestAccPreCheck(t)
common.TestAccPreCheckApigw(t)
},
ProviderFactories: common.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceInstanceFeatures_basic(),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestMatchResourceAttr(rName, "features.#", regexp.MustCompile(`^[1-9]([0-9]*)?$`)),
dcByName.CheckResourceExists(),
resource.TestMatchResourceAttr(byName, "features.0.updated_at",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
resource.TestCheckOutput("is_name_filter_useful", "true"),
dcByNotFoundName.CheckResourceExists(),
resource.TestCheckOutput("is_name_not_found_filter_useful", "true"),
),
},
},
})
}

func testAccDataSourceInstanceFeatures_basic() string {
return fmt.Sprintf(`
locals {
gateway_id = "%[1]s"
}

data "opentelekomcloud_apigw_gateway_features_v2" "test" {
gateway_id = local.gateway_id
}

# Filter by name
locals {
feature_name = data.opentelekomcloud_apigw_gateway_features_v2.test.features[0].name
}

data "opentelekomcloud_apigw_gateway_features_v2" "filter_by_name" {
gateway_id = local.gateway_id
name = local.feature_name
}

locals {
name_filter_result = [
for v in data.opentelekomcloud_apigw_gateway_features_v2.filter_by_name.features[*].name : v == local.feature_name
]
}

output "is_name_filter_useful" {
value = length(local.name_filter_result) > 0 && alltrue(local.name_filter_result)
}

# Filter by name (not found)
locals {
not_found_name = "not_found"
}

data "opentelekomcloud_apigw_gateway_features_v2" "filter_by_not_found_name" {
gateway_id = local.gateway_id
name = local.not_found_name
}

locals {
not_found_name_filter_result = [
for v in data.opentelekomcloud_apigw_gateway_features_v2.filter_by_not_found_name.features[*].name : strcontains(v, local.not_found_name)
]
}

output "is_name_not_found_filter_useful" {
value = length(local.not_found_name_filter_result) == 0
}
`, env.OS_APIGW_GATEWAY_ID)
}
Loading
Loading