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 4 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
10 changes: 10 additions & 0 deletions ovh/data_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
Description: "Version of the engine deployed on the cluster",
Computed: true,
},
"disk_size": {
Type: schema.TypeInt,
Description: "Disk size attributes of the cluster",
Computed: true,
},
"disk_type": {
Type: schema.TypeString,
Description: "Disk type attributes of the cluster",
Computed: true,
},
},
}
}
Expand Down
11 changes: 11 additions & 0 deletions ovh/resource_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ 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,
ValidateFunc: validateCloudProjectDatabaseDiskSize,
},
"disk_type": {
Type: schema.TypeString,
Description: "Disk type attributes of the cluster",
Computed: 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
30 changes: 23 additions & 7 deletions ovh/types_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type CloudProjectDatabaseResponse struct {
Status string `json:"status"`
SubnetId string `json:"subnetId"`
Version string `json:"version"`
Disk CloudProjectDatabaseDisk `json:"disk"`
}

func (s *CloudProjectDatabaseResponse) String() string {
Expand Down Expand Up @@ -71,6 +72,8 @@ func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
obj["plan"] = v.Plan
obj["status"] = v.Status
obj["version"] = v.Version
obj["disk_size"] = v.Disk.Size
obj["disk_type"] = v.Disk.Type

return obj
}
Expand Down Expand Up @@ -129,11 +132,22 @@ 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 {
Type string `json:"type,omitempty"`
Size int `json:"size,omitempty"`
}

func validateCloudProjectDatabaseDiskSize(v interface{}, k string) (ws []string, errors []error) {
errors = validateIsSupEqual(v.(int), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

only sup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first the goal of this check was to avoid making request to the OVH API with negative values that would failed every time. And thus, adding more check will be redundant.

return
}

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

opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int), Type: d.Get("disk_type").(string)}
return nil, opts
}

type CloudProjectDatabaseUpdateOpts struct {
AclsEnabled bool `json:"aclsEnabled,omitempty"`
Description string `json:"description,omitempty"`
Flavor string `json:"flavor,omitempty"`
Plan string `json:"plan,omitempty"`
RestApi bool `json:"restApi,omitempty"`
Version string `json:"version,omitempty"`
AclsEnabled bool `json:"aclsEnabled,omitempty"`
Description string `json:"description,omitempty"`
Flavor string `json:"flavor,omitempty"`
Plan string `json:"plan,omitempty"`
RestApi bool `json:"restApi,omitempty"`
Version string `json:"version,omitempty"`
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
}

func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
Expand All @@ -189,6 +204,7 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
opts.Plan = d.Get("plan").(string)
opts.Flavor = d.Get("flavor").(string)
opts.Version = d.Get("version").(string)
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int), Type: d.Get("disk_type").(string)}
return nil, opts
}

Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/cloud_project_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ The following attributes are exported:
* `plan` - Plan of the cluster.
* `status` - Current status of the cluster.
* `version` - The version of the engine in which the service should be deployed
* `disk_size` - Defines the disk size of the database service.
* `disk_type` - Defines the disk type 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_type` - Defines the disk type of the database service.
* `disk_type` - The disk type of the database service.

4 changes: 4 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,8 @@ 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

* `disk_type` - Defines the disk type 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_type` - Defines the disk type of the database service.
* `disk_type` - See Argument Reference above.


## Timeouts

Expand Down