Skip to content

Commit

Permalink
feat(GaussDBforMySQL): gaussdb mysql parameter template support copy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 authored Sep 10, 2024
1 parent 642383f commit f91709f
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 60 deletions.
79 changes: 75 additions & 4 deletions docs/resources/gaussdb_mysql_parameter_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
subcategory: "GaussDB(for MySQL)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_gaussdb_mysql_parameter_template"
description: ""
description: |-
Manages a GaussDB MySQL parameter template resource within HuaweiCloud.
---

# huaweicloud_gaussdb_mysql_parameter_template
Expand All @@ -11,9 +12,35 @@ Manages a GaussDB MySQL parameter template resource within HuaweiCloud.

## Example Usage

### create parameter template

```hcl
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "test_mysql_parameter_template"
}
```

### replica parameter template from existed configuration

```hcl
variable "source_configuration_id" {}
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "test_mysql_parameter_template"
name = "test_copy_from_configuration"
source_configuration_id = var.source_configuration_id
}
```

### replica parameter template from existed instance

```hcl
variable "instance_id" {}
variable "instance_configuration_id" {}
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "test_copy_from_instance"
instance_id = var.instance_id
instance_configuration_id = var.instance_configuration_id
}
```

Expand All @@ -38,6 +65,31 @@ The following arguments are supported:

Changing this parameter will create a new resource.

-> **NOTE:** It is mandatory when `datastore_engine` is specified.

* `source_configuration_id` - (Optional, String, ForceNew) Specifies the source parameter template ID.

Changing this parameter will create a new resource.

* `instance_id` - (Optional, String, ForceNew) Specifies the ID of the GaussDB MySQL instance.

Changing this parameter will create a new resource.

* `instance_configuration_id` - (Optional, String, ForceNew) Specifies the parameter template ID of the GaussDB MySQL
instance.

Changing this parameter will create a new resource.

-> **NOTE:** It is mandatory when `instance_id` is specified.

-> **NOTE:** 1. At most one of `datastore_engine`, `source_configuration_id` and `instance_id` can be specified.
<br>2. If `source_configuration_id` is specified, then the resource will replicate the parameter template specified
by `source_configuration_id`.
<br>3. If `instance_id` is specified, then the resource will replicate the parameter template of the GaussDB MySQL
instance specified by `instance_id`.
<br>4. If `source_configuration_id` and `instance_id` are both not specified, then a new parameter template will be
created directly.

* `parameter_values` - (Optional, Map) Specifies the mapping between parameter names and parameter values.
You can specify parameter values based on a default parameter template.

Expand All @@ -47,10 +99,10 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `created_at` - Indicates the creation time in the "yyyy-MM-ddTHH:mm:ssZ" format.
* `created_at` - Indicates the creation time in the **yyyy-MM-ddTHH:mm:ssZ** format.
T is the separator between calendar and hourly notation of time. Z indicates the time zone offset.

* `updated_at` - Indicates the update time in the "yyyy-MM-ddTHH:mm:ssZ" format.
* `updated_at` - Indicates the update time in the **yyyy-MM-ddTHH:mm:ssZ** format.
T is the separator between calendar and hourly notation of time. Z indicates the time zone offset.

## Import
Expand All @@ -60,3 +112,22 @@ The GaussDB Mysql parameter template can be imported using the `id`, e.g.
```bash
$ terraform import huaweicloud_gaussdb_mysql_parameter_template.test <id>
```

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
API response, security or some other reason. The missing attributes include: `source_configuration_id`, `instance_id`
and `instance_configuration_id`. It is generally recommended running `terraform plan` after importing an GaussDB MySQL
parameter template. You can then decide if changes should be applied to the GaussDB MySQL parameter template, or the
GaussDB MySQL parameter template definition should be updated to align with the instance. Also, you can ignore changes
as below.

```hcl
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
...
lifecycle {
ignore_changes = [
source_configuration_id, instance_id, instance_configuration_id,
]
}
}
```
17 changes: 17 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ var (
HW_BUILD_IMAGE_URL = os.Getenv("HW_BUILD_IMAGE_URL") // SWR Image URL for component deployment
HW_BUILD_IMAGE_URL_UPDATED = os.Getenv("HW_BUILD_IMAGE_URL_UPDATED") // SWR Image URL for component deployment update

HW_GAUSSDB_MYSQL_INSTANCE_ID = os.Getenv("HW_GAUSSDB_MYSQL_INSTANCE_ID")
HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID = os.Getenv("HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID")

HW_VOD_WATERMARK_FILE = os.Getenv("HW_VOD_WATERMARK_FILE")
HW_VOD_MEDIA_ASSET_FILE = os.Getenv("HW_VOD_MEDIA_ASSET_FILE")

Expand Down Expand Up @@ -1129,6 +1132,20 @@ func TestAccPreCheckImageUrlUpdated(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckGaussDBMysqlInstanceId(t *testing.T) {
if HW_GAUSSDB_MYSQL_INSTANCE_ID == "" {
t.Skip("HW_GAUSSDB_MYSQL_INSTANCE_ID must be set for GaussDB MySQL acceptance tests.")
}
}

// lintignore:AT003
func TestAccPreCheckGaussDBMysqlInstanceConfigurationId(t *testing.T) {
if HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID == "" {
t.Skip("HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID must be set for GaussDB MySQL acceptance tests.")
}
}

// lintignore:AT003
func TestAccPreCheckVODWatermark(t *testing.T) {
if HW_VOD_WATERMARK_FILE == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestAccGaussDBMysqlTemplate_basic(t *testing.T) {
})
}

func TestAccGaussDBMysqlTemplate_with_name(t *testing.T) {
func TestAccGaussDBMysqlTemplate_with_configuration(t *testing.T) {
var obj interface{}

name := acceptance.RandomAccResourceName()
Expand All @@ -122,21 +122,105 @@ func TestAccGaussDBMysqlTemplate_with_name(t *testing.T) {
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testParameterTemplate_with_name(name),
Config: testParameterTemplate_with_configuration(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "description",
"test gaussdb mysql parameter template"),
resource.TestCheckResourceAttr(rName, "datastore_engine", "gaussdb-mysql"),
resource.TestCheckResourceAttr(rName, "datastore_version", "8.0"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_offset", "5"),
resource.TestCheckResourceAttrSet(rName, "created_at"),
resource.TestCheckResourceAttrSet(rName, "updated_at"),
),
},
{
Config: testParameterTemplate_with_name(updateName),
Config: testParameterTemplate_with_configuration_update(name, updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", updateName),
resource.TestCheckResourceAttr(rName, "description",
"test gaussdb mysql parameter template update"),
resource.TestCheckResourceAttr(rName, "datastore_engine", "gaussdb-mysql"),
resource.TestCheckResourceAttr(rName, "datastore_version", "8.0"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_increment", "6"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_offset", "8"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"parameter_values",
"source_configuration_id",
},
},
},
})
}

func TestAccGaussDBMysqlTemplate_with_instance(t *testing.T) {
var obj interface{}

name := acceptance.RandomAccResourceName()
updateName := acceptance.RandomAccResourceName()
rName := "huaweicloud_gaussdb_mysql_parameter_template.test"

rc := acceptance.InitResourceCheck(
rName,
&obj,
getGaussDBMysqlTemplateResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckGaussDBMysqlInstanceId(t)
acceptance.TestAccPreCheckGaussDBMysqlInstanceConfigurationId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testParameterTemplate_with_instance(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "description",
"test gaussdb mysql parameter template"),
resource.TestCheckResourceAttr(rName, "datastore_engine", "gaussdb-mysql"),
resource.TestCheckResourceAttr(rName, "datastore_version", "8.0"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_increment", "4"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_offset", "5"),
resource.TestCheckResourceAttrSet(rName, "created_at"),
resource.TestCheckResourceAttrSet(rName, "updated_at"),
),
},
{
Config: testParameterTemplate_with_instance_update(updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "name", updateName),
resource.TestCheckResourceAttr(rName, "description",
"test gaussdb mysql parameter template update"),
resource.TestCheckResourceAttr(rName, "datastore_engine", "gaussdb-mysql"),
resource.TestCheckResourceAttr(rName, "datastore_version", "8.0"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_increment", "6"),
resource.TestCheckResourceAttr(rName, "parameter_values.auto_increment_offset", "8"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"parameter_values",
"instance_id",
"instance_configuration_id",
},
},
},
})
}
Expand Down Expand Up @@ -173,10 +257,83 @@ resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
`, name)
}

func testParameterTemplate_with_name(name string) string {
func testParameterTemplate_with_configuration(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_gaussdb_mysql_parameter_template" "source_template" {
name = "%[1]s_source"
datastore_engine = "gaussdb-mysql"
datastore_version = "8.0"
parameter_values = {
auto_increment_increment = "4"
}
}
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "%s"
name = "%[1]s"
description = "test gaussdb mysql parameter template"
source_configuration_id = huaweicloud_gaussdb_mysql_parameter_template.source_template.id
parameter_values = {
auto_increment_offset = "5"
}
}
`, name)
}

func testParameterTemplate_with_configuration_update(name, updateName string) string {
return fmt.Sprintf(`
resource "huaweicloud_gaussdb_mysql_parameter_template" "source_template" {
name = "%[1]s_source"
datastore_engine = "gaussdb-mysql"
datastore_version = "8.0"
parameter_values = {
auto_increment_increment = "4"
}
}
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "%[2]s"
description = "test gaussdb mysql parameter template update"
source_configuration_id = huaweicloud_gaussdb_mysql_parameter_template.source_template.id
parameter_values = {
auto_increment_increment = "6"
auto_increment_offset = "8"
}
}
`, name, updateName)
}

func testParameterTemplate_with_instance(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "%[1]s"
description = "test gaussdb mysql parameter template"
instance_id = "%[2]s"
instance_configuration_id = "%[3]s"
parameter_values = {
auto_increment_increment = "4"
auto_increment_offset = "5"
}
}
`, name, acceptance.HW_GAUSSDB_MYSQL_INSTANCE_ID, acceptance.HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID)
}

func testParameterTemplate_with_instance_update(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_gaussdb_mysql_parameter_template" "test" {
name = "%[1]s"
description = "test gaussdb mysql parameter template update"
instance_id = "%[2]s"
instance_configuration_id = "%[3]s"
parameter_values = {
auto_increment_increment = "6"
auto_increment_offset = "8"
}
}
`, name, acceptance.HW_GAUSSDB_MYSQL_INSTANCE_ID, acceptance.HW_GAUSSDB_MYSQL_INSTANCE_CONFIGURATION_ID)
}
Loading

0 comments on commit f91709f

Please sign in to comment.