-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APIGW]: gateway resource implementation (#2407)
[APIGW]: gateway resource implementation Summary of the Pull Request Basic gateway resource introduced for APIGW. PR Checklist Refers to: #2403 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed === RUN TestAccAPIGWv2Gateway_basic === PAUSE TestAccAPIGWv2Gateway_basic === CONT TestAccAPIGWv2Gateway_basic --- PASS: TestAccAPIGWv2Gateway_basic (395.95s) PASS === RUN TestAccAPIGWGatewayV2ImportBasic --- PASS: TestAccAPIGWGatewayV2ImportBasic (355.57s) PASS Process finished with the exit code 0 Process finished with the exit code 0 Reviewed-by: Anton Sidelnikov
- Loading branch information
1 parent
2cbbbb8
commit 0610319
Showing
8 changed files
with
758 additions
and
5 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,112 @@ | ||
--- | ||
subcategory: "APIG" | ||
--- | ||
|
||
Up-to-date reference of API arguments for Anti-DDoS service you can get at | ||
`https://docs.otc.t-systems.com/api-gateway/api-ref/dedicated_gateway_apis_v2/index.html`. | ||
|
||
# opentelekomcloud_apigw_gateway_v2 | ||
|
||
API Gateway (APIG) is a high-performance, high-availability, and high-security API hosting service that helps you build, | ||
manage, and deploy APIs at any scale. | ||
With just a few clicks, you can integrate internal systems, and selectively expose capabilities with minimal costs and risks. | ||
|
||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "opentelekomcloud_apigw_gateway_v2" "gateway" { | ||
name = "test-gateway" | ||
spec_id = "BASIC" | ||
vpc_id = var.vpc_id | ||
subnet_id = var.network_id | ||
security_group_id = var.default_secgroup.id | ||
availability_zones = ["eu-de-01", "eu-de-02"] | ||
description = "test gateway" | ||
bandwidth_size = 5 | ||
maintain_begin = "22:00:00" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required, String) Specifies gateway name. | ||
|
||
* `spec_id` - (Required, ForceNew, String) Gateway edition. Options: | ||
This resource provides the following timeouts configuration options: | ||
- `BASIC` | ||
- `PROFESSIONAL` | ||
- `ENTERPRISE` | ||
- `PLATINUM` | ||
|
||
* `vpc_id` - (Required, ForceNew, String) Specifies VPC ID. | ||
|
||
* `subnet_id` - (Required, ForceNew, String) Specifies network ID. | ||
|
||
* `security_group_id` - (Required, String) Specifies ID of the security group to which the gateway belongs. | ||
|
||
* `description` - (Optional, String) Specifies gateway description. | ||
|
||
* `availability_zones` - (Optional, List) Specifies gateway description. | ||
|
||
* `bandwidth_size` - (Optional, String) Specifies outbound access bandwidth. This parameter is required if public outbound | ||
access is enabled for the gateway. After you configure the bandwidth for the gateway, | ||
users can access resources on public networks. | ||
|
||
* `ingress_bandwidth_size` - (Optional, String) Specifies public inbound access bandwidth. This parameter is required if public | ||
inbound access is enabled for the gateway and loadbalancer_provider is set to elb. | ||
After you bind an EIP to the gateway, users can access APIs in the gateway from public networks using the EIP. | ||
|
||
* `loadbalancer_provider` - (Optional, String) Specifies type of the load balancer used by the gateway. | ||
This resource provides the following timeouts configuration options: | ||
- `elb` | ||
|
||
* `maintain_begin` - (Optional, String) Specifies start time of the maintenance time window. | ||
It must be in the format "xx:00:00". The value of xx can be 02, 06, 10, 14, 18, or 22. | ||
|
||
## Attributes Reference | ||
|
||
All above argument parameters can be exported as attribute parameters along with attribute reference. | ||
|
||
* `maintain_end` - End time of the maintenance time window. It must be in the format "xx:00:00". | ||
There is a 4-hour difference between the start time and end time. | ||
|
||
* `vpc_ingress_address` - VPC ingress address. | ||
|
||
* `public_egress_address` - IP address for public outbound access. | ||
|
||
* `supported_features` - Supported features. | ||
|
||
* `status` - Instance status. | ||
|
||
* `project_id` - Instance project id. | ||
|
||
* `region` - Instance region. | ||
|
||
* `vpcep_service_name` - Name of a VPC endpoint service. | ||
|
||
* `private_egress_addresses` - List of private egress addresses. | ||
* | ||
## Import | ||
|
||
APIG Gateway can be imported using the `gateway_id`, e.g. | ||
|
||
```shell | ||
$ terraform import opentelekomcloud_apigw_gateway_v2.gateway c1881895-cdcb-4d23-96cb-032e6a3ee667 | ||
``` | ||
|
||
Note that the imported state may not be identical to your resource definition, due to `ingress_bandwidth_size` missing from the | ||
API response. It is generally recommended running `terraform plan` after importing a gateway. | ||
|
||
``` | ||
resource "opentelekomcloud_apigw_gateway_v2" "gateway" { | ||
... | ||
lifecycle { | ||
ignore_changes = [ | ||
ingress_bandwidth_size | ||
] | ||
} | ||
} |
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
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
170 changes: 170 additions & 0 deletions
170
opentelekomcloud/acceptance/apigw/resource_opentelekomcloud_apigw_gateway_v2_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,170 @@ | ||
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" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/gateway" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/autoscaling/v1/configurations" | ||
"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 resourceName = "opentelekomcloud_apigw_gateway_v2.gateway" | ||
|
||
func TestAccAPIGWv2Gateway_basic(t *testing.T) { | ||
var gatewayConfig gateway.Gateway | ||
name := fmt.Sprintf("gateway-%s", acctest.RandString(10)) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
common.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: testAccCheckAPIGWv2GatewayDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAPIGWv2GatewayBasic(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAPIGWv2GatewayExists(resourceName, &gatewayConfig), | ||
resource.TestCheckResourceAttr(resourceName, "name", name), | ||
resource.TestCheckResourceAttr(resourceName, "spec_id", "BASIC"), | ||
resource.TestCheckResourceAttr(resourceName, "description", "test gateway"), | ||
resource.TestCheckResourceAttr(resourceName, "bandwidth_size", "5"), | ||
resource.TestCheckResourceAttr(resourceName, "maintain_begin", "22:00:00"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAPIGWv2GatewayUpdated(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAPIGWv2GatewayExists(resourceName, &gatewayConfig), | ||
resource.TestCheckResourceAttr(resourceName, "name", name+"-updated"), | ||
resource.TestCheckResourceAttr(resourceName, "description", "test gateway 2"), | ||
resource.TestCheckResourceAttr(resourceName, "bandwidth_size", "0"), | ||
resource.TestCheckResourceAttr(resourceName, "maintain_begin", "02:00:00"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAPIGWv2GatewayDestroy(s *terraform.State) error { | ||
config := common.TestAccProvider.Meta().(*cfg.Config) | ||
client, err := config.AutoscalingV1Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return fmt.Errorf("error creating OpenTelekomCloud AutoScalingV1 client: %w", err) | ||
} | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "opentelekomcloud_apigw_gateway_v2" { | ||
continue | ||
} | ||
|
||
_, err := configurations.Get(client, rs.Primary.ID) | ||
if err == nil { | ||
return fmt.Errorf("AS configuration still exists") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckAPIGWv2GatewayExists(n string, configuration *gateway.Gateway) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no ID is set") | ||
} | ||
|
||
config := common.TestAccProvider.Meta().(*cfg.Config) | ||
client, err := config.APIGWV2Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return fmt.Errorf("error creating OpenTelekomCloud AutoScalingV1 client: %w", err) | ||
} | ||
|
||
found, err := gateway.Get(client, rs.Primary.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if found.ID != rs.Primary.ID { | ||
return fmt.Errorf("autoscaling Configuration not found") | ||
} | ||
configuration = found | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func TestAccAPIGWGatewayV2ImportBasic(t *testing.T) { | ||
name := fmt.Sprintf("gateway-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { common.TestAccPreCheck(t) }, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: testAccCheckAPIGWv2GatewayDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAPIGWv2GatewayBasic(name), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"ingress_bandwidth_size", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAPIGWv2GatewayBasic(gatewayName string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "opentelekomcloud_apigw_gateway_v2" "gateway"{ | ||
name = "%s" | ||
spec_id = "BASIC" | ||
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id | ||
subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id | ||
security_group_id = data.opentelekomcloud_networking_secgroup_v2.default_secgroup.id | ||
availability_zones = ["eu-de-01", "eu-de-02"] | ||
description = "test gateway" | ||
bandwidth_size = 5 | ||
maintain_begin = "22:00:00" | ||
ingress_bandwidth_size = 5 | ||
} | ||
`, common.DataSourceSubnet, common.DataSourceSecGroupDefault, gatewayName) | ||
} | ||
|
||
func testAccAPIGWv2GatewayUpdated(gatewayName string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "opentelekomcloud_apigw_gateway_v2" "gateway"{ | ||
name = "%s-updated" | ||
spec_id = "BASIC" | ||
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id | ||
subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id | ||
security_group_id = data.opentelekomcloud_networking_secgroup_v2.default_secgroup.id | ||
availability_zones = ["eu-de-01", "eu-de-02"] | ||
description = "test gateway 2" | ||
bandwidth_size = 0 | ||
maintain_begin = "02:00:00" | ||
ingress_bandwidth_size = 5 | ||
} | ||
`, common.DataSourceSubnet, common.DataSourceSecGroupDefault, gatewayName) | ||
} |
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
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.