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

[CSS] Add tags support for cluster #1639

Merged
merged 1 commit into from Mar 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/css_cluster_v1.md
Expand Up @@ -67,6 +67,8 @@ lowercase letters, numbers, and special characters (`~!@#$%^&*()-_=+\\|[{}];:,<.

* `expect_node_num` - (Optional) Number of cluster instances. The value range is `1` to `32`.

* `tags` - (Optional) Tags key/value pairs to associate with the cluster.

The `node_config` block supports:

* `availability_zone` - (Optional) Availability zone (AZ). Changing this parameter will create a new resource.
Expand Down
Expand Up @@ -49,6 +49,30 @@ func TestAccCssClusterV1_basic(t *testing.T) {
})
}

func TestAccCssClusterV1_tags(t *testing.T) {
name := fmt.Sprintf("css-%s", acctest.RandString(10))
var cluster clusters.Cluster

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
common.TestAccPreCheck(t)
quotas.BookMany(t, sharedFlavorQuotas(t, 2, 40))
},
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckCssClusterV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccCssClusterV1Tags(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckCssClusterV1Exists(resourceClusterName, &cluster),
resource.TestCheckResourceAttr(resourceClusterName, "nodes.#", "1"),
resource.TestCheckResourceAttr(resourceClusterName, "tags.say", "hi"),
),
},
},
})
}

func TestAccCssClusterV1_validateDiskAndFlavor(t *testing.T) {
name := fmt.Sprintf("css-%s", acctest.RandString(10))

Expand Down Expand Up @@ -193,6 +217,43 @@ resource "opentelekomcloud_css_cluster_v1" "cluster" {
`, common.DataSourceSecGroupDefault, common.DataSourceSubnet, name, env.OS_AVAILABILITY_ZONE)
}

func testAccCssClusterV1Tags(name string) string {
return fmt.Sprintf(`
%s

%s

resource "opentelekomcloud_css_cluster_v1" "cluster" {
expect_node_num = 1
name = "%s"
node_config {
flavor = "css.medium.8"
network_info {
security_group_id = data.opentelekomcloud_networking_secgroup_v2.default_secgroup.id
network_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
}
volume {
volume_type = "COMMON"
size = 40
}

availability_zone = "%s"
}
datastore {
version = "7.6.2"
}
enable_https = true
enable_authority = true
admin_pass = "QwertyUI!"

tags = {
say = "hi"
}
}
`, common.DataSourceSecGroupDefault, common.DataSourceSubnet, name, env.OS_AVAILABILITY_ZONE)
}

func testAccCssClusterV1TooSmall(name string) string {
return fmt.Sprintf(`
%s
Expand Down
Expand Up @@ -13,6 +13,7 @@ import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/flavors"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common"

"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr"
Expand All @@ -38,7 +39,6 @@ func ResourceCssClusterV1() *schema.Resource {
Required: true,
ForceNew: true,
},

"node_config": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -111,39 +111,33 @@ func ResourceCssClusterV1() *schema.Resource {
},
},
},

"enable_https": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
ForceNew: true,
},

"enable_authority": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
ForceNew: true,
},

"admin_pass": {
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"enable_authority"},
ForceNew: true,
},

"expect_node_num": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
},

"created": {
Type: schema.TypeString,
Computed: true,
},

"datastore": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -167,12 +161,16 @@ func ResourceCssClusterV1() *schema.Resource {
},
},
},

"tags": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
ValidateFunc: common.ValidateTags,
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
},

"nodes": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -193,7 +191,6 @@ func ResourceCssClusterV1() *schema.Resource {
},
},
},

"updated": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -230,6 +227,7 @@ func resourceCssClusterV1Create(ctx context.Context, d *schema.ResourceData, met
},
AuthorityEnabled: d.Get("enable_authority").(bool),
AdminPassword: d.Get("admin_pass").(string),
Tags: common.ExpandResourceTags(d.Get("tags").(map[string]interface{})),
}
if enable, ok := d.GetOk("enable_https"); ok {
opts.HttpsEnabled = fmt.Sprint(enable.(bool))
Expand Down Expand Up @@ -282,9 +280,9 @@ func resourceCssClusterV1Read(_ context.Context, d *schema.ResourceData, meta in
d.Set("created", cluster.Created),
d.Set("updated", cluster.Updated),
d.Set("endpoint", cluster.Endpoint),

d.Set("nodes", extractNodes(cluster)),
d.Set("datastore", extractDatastore(cluster)),
d.Set("tags", common.TagsToMap(cluster.Tags)),
)

if err := mErr.ErrorOrNil(); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/css-cluster-tags-de43792ca6f6bd59.yaml
@@ -0,0 +1,5 @@
---
enhancements:
- |
**[CSS]** Add ``tags`` argument to ``resource/opentelekomcloud_css_cluster_v1``
(`#1639 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1639>`_)