-
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.
[Feat] DDM: Add resource ddm v1 (#2692)
[Feat] DDM: Add resource ddm v1 Summary of the Pull Request Adds DDM instance resource to OTC provider PR Checklist Refers to: #2573 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed === RUN TestAccDdmInstancesV1_basic --- PASS: TestAccDdmInstancesV1_basic (950.74s) PASS Process finished with exit code 0 Reviewed-by: Anton Sidelnikov Reviewed-by: Muneeb H. Jan <muneebhafeezjan@gmail.com>
- Loading branch information
1 parent
78230d9
commit 6421821
Showing
9 changed files
with
865 additions
and
2 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,178 @@ | ||
--- | ||
subcategory: "Distributed Database Middleware (DDM)" | ||
layout: "opentelekomcloud" | ||
page_title: "OpenTelekomCloud: opentelekomcloud_ddm_instance_v1" | ||
sidebar_current: "docs-opentelekomcloud-resource-ddm-instance-v1" | ||
description: |- | ||
Manages a DDM Instance resource within OpenTelekomCloud. | ||
--- | ||
|
||
Up-to-date reference of API arguments for DDS instance you can get at | ||
[documentation portal](https://docs.otc.t-systems.com/distributed-database-middleware/api-ref/apis_recommended/ddm_instances) | ||
|
||
# opentelekomcloud_ddm_instance_v1 | ||
|
||
Manages DDM instance resource within OpenTelekomCloud | ||
|
||
## Example Usage: Creating a basic DDM instance with 2 nodes | ||
```hcl | ||
variable "flavor_id" {} | ||
variable "engine_id" {} | ||
variable "vpc_id" {} | ||
variable "subnet_id" {} | ||
variable "security_group_id" {} | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance" | ||
availability_zones = ["eu-de-01", "eu-de-02", "eu-de-03"] | ||
flavor_id = var.flavor_id | ||
node_num = 2 | ||
engine_id = var.engine_id | ||
vpc_id = var.vpc_id | ||
subnet_id = var.subnet_id | ||
security_group_id = var.security_group.id | ||
purge_rds_on_delete = true | ||
} | ||
``` | ||
|
||
## Example Usage: Creating a DDM instance with custom credentials | ||
```hcl | ||
variable "flavor_id" {} | ||
variable "engine_id" {} | ||
variable "vpc_id" {} | ||
variable "subnet_id" {} | ||
variable "security_group_id" {} | ||
variable "username" {} | ||
variable "password" {} | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance" | ||
availability_zones = ["eu-de-01", "eu-de-02", "eu-de-03"] | ||
flavor_id = var.flavor_id | ||
node_num = 2 | ||
engine_id = var.engine_id | ||
vpc_id = var.vpc_id | ||
subnet_id = var.subnet_id | ||
security_group_id = var.security_group.id | ||
purge_rds_on_delete = true | ||
username = var.username | ||
password = var.password | ||
} | ||
``` | ||
|
||
## Example Usage: Creating a DDM instance with custom time zone | ||
```hcl | ||
variable "flavor_id" {} | ||
variable "engine_id" {} | ||
variable "vpc_id" {} | ||
variable "subnet_id" {} | ||
variable "security_group_id" {} | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance" | ||
availability_zones = ["eu-de-01", "eu-de-02", "eu-de-03"] | ||
flavor_id = var.flavor_id | ||
node_num = 2 | ||
engine_id = var.engine_id | ||
vpc_id = var.vpc_id | ||
subnet_id = var.subnet_id | ||
security_group_id = var.security_group.id | ||
purge_rds_on_delete = true | ||
time_zone = "UTC+01:00" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required, String) Specifies the DDM instance name. The DDM instance name of the same | ||
type is unique in the same tenant. It can be 4 to 64 characters long. It must start with a letter and it can only contain etters, digits, and hyphens (-). | ||
|
||
* `availability_zones` - (Required, List, ForceNew) Specifies the list of availability zones. | ||
|
||
* `vpc_id` - (Required, String, ForceNew) Specifies the VPC ID. | ||
|
||
* `subnet_id` - (Required, String, ForceNew) Specifies the subnet Network ID. | ||
|
||
* `security_group_id` - (Required, String) Specifies the security group ID of the DDM instance. | ||
|
||
* `node_num` - (Required, Integer) Specifies the disk encryption ID of the instance. | ||
|
||
* `flavor_id` - (Required, String, ForceNew) Specifies the flavor ID of the instance nodes. | ||
|
||
* `engine_id` - (Required, String, ForceNew) Specifies the Engine ID of the instance. | ||
|
||
* `time_zone` - (Optional, String, ForceNew) Specifies the timezone. Valid formats are `UTC+12:00`, `UTC+11:00`, ... ,`UTC+01:00`, `UTC`, `UTC-01:00`, ... , `UTC-11:00`, `UTC-12:00` | ||
|
||
* `username` - (Optional, String, ForceNew) Specifies the Administrator username of the DDM instance. It can be 1 to 32 characters long and can contain letters, digits, and underscores (_). It must start with a letter. | ||
|
||
* `password` - (Optional, String) Specifies the Administrator password of the DDM instance. it can be 8 to 32 characters long. It must be a combination of uppercase letters, lowercase letters, digits, and the following special characters: `~ ! @ # % ^ * - _ = + ?`. It must be a strong password to improve security and prevent security risks such as brute force cracking. | ||
|
||
* `param_group_id` - (Optional, String, ForceNew) Specifies the parameters group ID. | ||
|
||
* `purge_rds_on_delete` - (Optional, Boolean) Specifies whether data stored on the associated DB instances is deleted. The value can be: `true` or `false` (default). | ||
|
||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `region` - The region of the DDM instance. | ||
* `name` - See Argument Reference above. | ||
* `availability_zones` - See Argument Reference above. | ||
* `vpc_id` - See Argument Reference above. | ||
* `subnet_id` - See Argument Reference above. | ||
* `security_group_id` - See Argument Reference above. | ||
* `node_num` - See Argument Reference above. | ||
* `flavor_id` - See Argument Reference above. | ||
* `engine_id` - See Argument Reference above. | ||
* `time_zone` - See Argument Reference above. | ||
* `username` - See Argument Reference above. | ||
* `password` - See Argument Reference above. | ||
* `param_group_id` - See Argument Reference above. | ||
* `purge_rds_on_delete` - See Argument Reference above. | ||
* `status` - Indicates the DDM instance status. | ||
* `access_IP` - Indicates the DDM access IP. | ||
* `access_port` - Indicates the DDM access port. | ||
* `created_at` - Indicates the creation time. | ||
* `updated_at` - Indicates the update time. | ||
* `availability_zone` - Indicates the availability zone of DDM instance. | ||
* `node_status` - Indicates the DDM nodes status. | ||
* `nodes` - Indicates the instance nodes information. Structure is documented below. | ||
|
||
The `nodes` block contains: | ||
|
||
- `ip` - Indicates the node IP. | ||
- `port` - Indicates the node port. | ||
- `status` - Indicates the node status. | ||
|
||
|
||
## Import | ||
|
||
DDMv1 Instance can be imported using the `id`, e.g. | ||
|
||
```shell | ||
terraform import opentelekomcloud_ddm_instance_v1.instance_1 c1851195-cdcb-4d23-96cb-032e6a3ee667 | ||
``` | ||
|
||
## Notes | ||
|
||
But due to some attributes missing from the API response, it's required to ignore changes as below: | ||
|
||
```hcl | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
# ... | ||
lifecycle { | ||
ignore_changes = [ | ||
availability_zones, | ||
flavor_id, | ||
engine_id, | ||
time_zone, | ||
password, | ||
purge_rds_on_delete | ||
] | ||
} | ||
} | ||
``` |
141 changes: 141 additions & 0 deletions
141
opentelekomcloud/acceptance/ddm/resource_opentelekomcloud_ddm_instance_v1_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,141 @@ | ||
package acceptance | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
|
||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances" | ||
|
||
"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 ddmInstanceResourceName = "opentelekomcloud_ddm_instance_v1.instance_1" | ||
|
||
func getDDMInstanceResourceFunc(cfg *cfg.Config, state *terraform.ResourceState) (interface{}, error) { | ||
client, err := cfg.DdmV1Client(env.OS_REGION_NAME) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating SDRS Client: %s", err) | ||
} | ||
return instances.QueryInstanceDetails(client, state.Primary.ID) | ||
} | ||
|
||
func TestAccDdmInstancesV1_basic(t *testing.T) { | ||
var instance instances.QueryInstanceDetailsResponse | ||
rc := common.InitResourceCheck( | ||
ddmInstanceResourceName, | ||
&instance, | ||
getDDMInstanceResourceFunc, | ||
) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { common.TestAccPreCheck(t) }, | ||
ProviderFactories: common.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDdmInstanceV1Basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "name", "ddm-instance"), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "node_num", "2"), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "username", "test_user"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDdmInstanceV1ScaleUp, | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "name", "ddm-instance-scale-up"), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "node_num", "3"), | ||
), | ||
}, | ||
{ | ||
Config: testAccDdmInstanceV1ScaleDown, | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "name", "ddm-instance-scale-down"), | ||
resource.TestCheckResourceAttr(ddmInstanceResourceName, "node_num", "1"), | ||
), | ||
}, | ||
{ | ||
ResourceName: ddmInstanceResourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{ | ||
"availability_zones", | ||
"flavor_id", | ||
"engine_id", | ||
"time_zone", | ||
"password", | ||
"param_group_id", | ||
"purge_rds_on_delete", | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testAccDdmInstanceV1Basic = fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance" | ||
availability_zones = ["%s"] | ||
flavor_id = "941b5a6d-3485-329e-902c-ffd49d352f16" | ||
node_num = 2 | ||
engine_id = "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4" | ||
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 | ||
time_zone = "UTC+01:00" | ||
username = "test_user" | ||
password = "test!-acc-Password-V1!" | ||
} | ||
`, common.DataSourceSubnet, common.DataSourceSecGroupDefault, env.OS_AVAILABILITY_ZONE) | ||
|
||
var testAccDdmInstanceV1ScaleUp = fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance-scale-up" | ||
availability_zones = ["%s"] | ||
flavor_id = "941b5a6d-3485-329e-902c-ffd49d352f16" | ||
node_num = 3 | ||
engine_id = "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4" | ||
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 | ||
time_zone = "UTC+01:00" | ||
username = "test_user" | ||
password = "test!-acc-Password-V1!" | ||
} | ||
`, common.DataSourceSubnet, common.DataSourceSecGroupDefault, env.OS_AVAILABILITY_ZONE) | ||
|
||
var testAccDdmInstanceV1ScaleDown = fmt.Sprintf(` | ||
%s | ||
%s | ||
resource "opentelekomcloud_ddm_instance_v1" "instance_1" { | ||
name = "ddm-instance-scale-down" | ||
availability_zones = ["%s"] | ||
flavor_id = "941b5a6d-3485-329e-902c-ffd49d352f16" | ||
node_num = 1 | ||
engine_id = "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4" | ||
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 | ||
time_zone = "UTC+01:00" | ||
username = "test_user" | ||
password = "test!-acc-Password-V2!" | ||
purge_rds_on_delete = true | ||
} | ||
`, common.DataSourceSubnet, common.DataSourceSecGroupDefault, env.OS_AVAILABILITY_ZONE) |
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.