-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Feat] DDM: Add resource ddm v1 #2692
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
10597b3
[Feat.] Add DDM clients to config
muneeb-jan 2e5b338
[Feat.] Add DDM common function and constants
muneeb-jan 3c8382e
[Feat.] Add resource_opentelekom_cloud_ddm_instance_v1
muneeb-jan 9bdc810
[Feat.] Add opentelekomcloud_ddm_instance_v1 to provider
muneeb-jan 5ce2d48
[Feat.] Add wait to scaling
muneeb-jan 1ae5860
[Test] Add resource_opentelekomcloud_ddm_instance_v1 test
muneeb-jan b3eef1b
[Fix] Fix order of update operations
muneeb-jan 95d5481
[Test] Ignore engine_id and flavor_id in import test
muneeb-jan 374d70d
Merge branch 'devel' into add-ddm-instance-schema
muneeb-jan 2f8c0a8
[Feat.] Add credentials update feature
muneeb-jan 8947700
[Doc.] Add doc ddm_instance_v1
muneeb-jan 5a543c1
[Test] Add more parameters to create and update
muneeb-jan a133c42
[Doc/Fix] Add more non-importable attributes
muneeb-jan 607cf49
[Style] Fix linting
muneeb-jan 5982454
[Doc] Add release note
muneeb-jan d3f2da5
[Fix] Documentation and validators
anton-sidelnikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,168 @@ | ||
--- | ||
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: | ||
|
||
* `region` - (Optional, String, ForceNew) Specifies the region of the DDM instance. | ||
|
||
* `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` - See Argument Reference above. | ||
* `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 | ||
``` | ||
|
||
Following attributes are not properly imported. | ||
* `availability_zones` | ||
* `flavor_id` | ||
* `engine_id` | ||
* `time_zone` | ||
* `password` | ||
* `param_group_id` | ||
* `purge_rds_on_delete` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change for: NotesBut due to some attributes missing from the API response, it's required to ignore changes as below: resource "opentelekomcloud_ddm_instance_v1" "instance_1" {
# ...
lifecycle {
ignore_changes = [
availability_zones,
flavor_id,
engine_id,
time_zone,
password,
]
}
} |
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
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,34 @@ | ||
package ddm | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
ddmv1instances "github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances" | ||
) | ||
|
||
const ( | ||
errCreationV1Client = "error creating OpenTelekomCloud DDMv1 client: %w" | ||
errCreationV2Client = "error creating OpenTelekomCloud DDMv2 client: %w" | ||
errCreationV3Client = "error creating OpenTelekomCloud DDMv3 client: %w" | ||
keyClientV1 = "ddm-v1-client" | ||
keyClientV2 = "ddm-v2-client" | ||
keyClientV3 = "ddm-v3-client" | ||
) | ||
|
||
func instanceStateRefreshFunc(client *golangsdk.ServiceClient, instanceID string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
instanceList, err := ddmv1instances.QueryInstances(client, ddmv1instances.QueryInstancesOpts{}) | ||
if err != nil { | ||
return nil, "Error retrieving DDM v1 Instances", err | ||
} | ||
if len(instanceList) == 0 { | ||
return nil, "DELETED", nil | ||
} | ||
for _, instance := range instanceList { | ||
if instance.Id == instanceID { | ||
return instance, instance.Status, nil | ||
} | ||
} | ||
return nil, "DELETED", nil | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to attributes