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

add port and nodes attributes for dds instance #349

Merged
merged 1 commit into from
Jun 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions huaweicloud/resource_huaweicloud_dds_instance_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
17 changes: 16 additions & 1 deletion website/docs/r/dds_instance_v3.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.