Skip to content

Commit

Permalink
add new fields to the mongodbatlas_cluster resource
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaykarle committed Jan 9, 2018
1 parent da0e806 commit ed37505
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions mongodbatlas/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ func resourceCluster() *schema.Resource {
Optional: true,
Default: 3,
},
"num_shards": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 1,
},
"paused": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"disk_gb_enabled": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"identifier": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand All @@ -78,6 +93,26 @@ func resourceCluster() *schema.Resource {
Optional: true,
Computed: true,
},
"mongodb_version": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"mongo_uri": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"mongo_uri_updated": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"mongo_uri_with_options": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
Expand All @@ -91,13 +126,19 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error {
RegionName: d.Get("region").(string),
InstanceSizeName: d.Get("size").(string),
}
autoScaling := mongodb.AutoScaling{
DiskGBEnabled: d.Get("disk_gb_enabled").(bool),
}
params := mongodb.Cluster{
Name: d.Get("name").(string),
MongoDBMajorVersion: d.Get("mongodb_major_version").(string),
ProviderSettings: providerSettings,
BackupEnabled: d.Get("backup").(bool),
ReplicationFactor: d.Get("replication_factor").(int),
DiskSizeGB: d.Get("disk_size_gb").(float64),
NumShards: d.Get("num_shards").(int),
Paused: d.Get("paused").(bool),
AutoScaling: autoScaling,
}

cluster, _, err := client.Clusters.Create(d.Get("group").(string), &params)
Expand Down Expand Up @@ -144,9 +185,16 @@ func resourceClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("backing_provider", c.ProviderSettings.BackingProviderName)
d.Set("region", c.ProviderSettings.RegionName)
d.Set("disk_size_gb", c.DiskSizeGB)
d.Set("disk_gb_enabled", c.AutoScaling.DiskGBEnabled)
d.Set("replication_factor", c.ReplicationFactor)
d.Set("identifier", c.ID)
d.Set("state", c.StateName)
d.Set("num_shards", c.NumShards)
d.Set("paused", c.Paused)
d.Set("mongodb_version", c.MongoDBVersion)
d.Set("mongo_uri", c.MongoURI)
d.Set("mongo_uri_updated", c.MongoURIUpdated)
d.Set("mongo_uri_with_options", c.MongoURIWithOptions)

return nil
}
Expand All @@ -172,6 +220,18 @@ func resourceClusterUpdate(d *schema.ResourceData, meta interface{}) error {
c.ReplicationFactor = d.Get("replication_factor").(int)
requestUpdate = true
}
if d.HasChange("num_shards") {
c.NumShards = d.Get("num_shards").(int)
requestUpdate = true
}
if d.HasChange("paused") {
c.Paused = d.Get("paused").(bool)
requestUpdate = true
}
if d.HasChange("disk_gb_enabled") {
c.AutoScaling.DiskGBEnabled = d.Get("disk_gb_enabled").(bool)
requestUpdate = true
}

if requestUpdate {
// Set read-only fields to an empty string to make the API happy
Expand Down

0 comments on commit ed37505

Please sign in to comment.