diff --git a/huaweicloud/resource_huaweicloud_dds_instance_v3.go b/huaweicloud/resource_huaweicloud_dds_instance_v3.go index 3133c2668e..61abca42d5 100644 --- a/huaweicloud/resource_huaweicloud_dds_instance_v3.go +++ b/huaweicloud/resource_huaweicloud_dds_instance_v3.go @@ -181,6 +181,46 @@ func resourceDdsInstanceV3() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "port": { + Type: schema.TypeInt, + Computed: true, + }, + "nodes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "role": { + Type: schema.TypeString, + Computed: true, + }, + "private_ip": { + Type: schema.TypeString, + Computed: true, + }, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, } } @@ -344,6 +384,7 @@ func resourceDdsInstanceV3Read(d *schema.ResourceData, meta interface{}) error { d.Set("mode", instance.Mode) d.Set("db_username", instance.DbUserName) d.Set("status", instance.Status) + d.Set("port", instance.Port) sslEnable := true if instance.Ssl == 0 { @@ -367,6 +408,13 @@ func resourceDdsInstanceV3Read(d *schema.ResourceData, meta interface{}) error { } backupStrategyList = append(backupStrategyList, backupStrategy) d.Set("backup_strategy", backupStrategyList) + + // save nodes attribute + err = d.Set("nodes", flattenDdsInstanceV3Nodes(instance)) + if err != nil { + return fmt.Errorf("Error setting nodes of DDS instance, err: %s", err) + } + return nil } @@ -400,3 +448,23 @@ func resourceDdsInstanceV3Delete(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Successfully deleted instance %s", instanceId) return nil } + +func flattenDdsInstanceV3Nodes(dds instances.InstanceResponse) interface{} { + nodesList := make([]map[string]interface{}, 0) + for _, group := range dds.Groups { + groupType := group.Type + for _, Node := range group.Nodes { + node := map[string]interface{}{ + "type": groupType, + "id": Node.Id, + "name": Node.Name, + "role": Node.Role, + "status": Node.Status, + "private_ip": Node.PrivateIP, + "public_ip": Node.PublicIP, + } + nodesList = append(nodesList, node) + } + } + return nodesList +} diff --git a/website/docs/r/dds_instance_v3.html.markdown b/website/docs/r/dds_instance_v3.html.markdown index 9d6983586f..4e53bcba99 100644 --- a/website/docs/r/dds_instance_v3.html.markdown +++ b/website/docs/r/dds_instance_v3.html.markdown @@ -189,4 +189,19 @@ The following attributes are exported: * `flavor` - See Argument Reference above. * `backup_strategy` - See Argument Reference above. * `db_username` - Indicates the DB Administator name. -* `status` - Indicates the the DB instance status +* `status` - Indicates the the DB instance status. +* `port` - Indicates the database port number. The port range is 2100 to 9500. +* `nodes` - Indicates the instance nodes information. Structure is documented below. + +The `nodes` block contains: + + - `id` - Indicates the node ID. + - `name` - Indicates the node name. + - `role` - Indicates the node role. + - `type` - Indicates the node type. + - `private_ip` - Indicates the private IP address of a node. This parameter is valid only for + mongos nodes, replica set instances, and single node instances. + - `public_ip` - Indicates the EIP that has been bound on a node. This parameter is valid only for + mongos nodes of cluster instances, primary nodes and secondary nodes of replica set instances, + and single node instances. + - `status` - Indicates the node status.