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 disk in database resource creation #333

Merged
merged 5 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions ovh/resource_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ func resourceCloudProjectDatabase() *schema.Resource {
Description: "Current status of the cluster",
Computed: true,
},
"disk_size": {
Type: schema.TypeInt,
Description: "Disk size attributes of the cluster",
Optional: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ValidateFunc to check here that disk_size is > 0.
Like in ovh/resource_cloud_project_database_kafka_topic.go

},
}
}
Expand Down
12 changes: 12 additions & 0 deletions ovh/types_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ type CloudProjectDatabaseCreateOpts struct {
Description string `json:"description,omitempty"`
NetworkId string `json:"networkId,omitempty"`
NodesPattern CloudProjectDatabaseNodesPattern `json:"nodesPattern,omitempty"`
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
Plan string `json:"plan"`
SubnetId string `json:"subnetId,omitempty"`
Version string `json:"version"`
}

type CloudProjectDatabaseDisk struct {
Size int `json:"size"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omitempty

}

type CloudProjectDatabaseNodesPattern struct {
Flavor string `json:"flavor"`
Number int `json:"number"`
Expand Down Expand Up @@ -164,6 +169,13 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
opts.SubnetId = nodes[0].SubnetId
opts.Version = d.Get("version").(string)

diskSize, ok := d.Get("disk_size").(int)
if ok {
if diskSize < 0 {
return fmt.Errorf("the disk size needs to be positive"), nil
}
opts.Disk = CloudProjectDatabaseDisk{diskSize}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need with both previous validateFunc and the omitempty.
You can just

opts.Disk = CloudProjectDatabaseDisk{
  Size: d.Get("disk_size").(int)
}

like CloudProjectDatabaseM3dbNamespaceCreateOpts Retention field

return nil, opts
}

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/cloud_project_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ The following arguments are supported:

* `opensearch_acls_enabled` - (Optional) Defines whether the ACLs are enabled on an OpenSearch cluster

* `disk_size` - (Optional) Defines the disk size of the database service.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `disk_size` - (Optional) Defines the disk size of the database service.
* `disk_size` - (Optional) The disk size of the database service.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to know the unit too?

    disk_size               = 80

As a user I don't know "80" what? :-)


* `plan` - (Required) Plan of the cluster.
Enum: "essential", "business", "enterprise".

Expand Down Expand Up @@ -243,6 +245,7 @@ The following attributes are exported:
* `plan` - See Argument Reference above.
* `status` - Current status of the cluster.
* `version` - See Argument Reference above.
* `disk_size` - See Argument Reference above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add disk_type as computed, need it here


## Timeouts

Expand Down