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 2 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
6 changes: 6 additions & 0 deletions ovh/resource_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ 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,
},
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
37 changes: 30 additions & 7 deletions ovh/types_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/go-ovh/ovh"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
"github.com/ybriffa/rfc3339"
)

Expand All @@ -32,6 +33,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 +73,7 @@ func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
obj["plan"] = v.Plan
obj["status"] = v.Status
obj["version"] = v.Version
obj["disk"] = v.Disk.ToMap()
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be align with schema because that will be set in terraform state an compare with the schema:

obj["disk_size"] = v.Disk.Size
obj["disk_type"] = v.Disk.Type // This need to add disk_type as computed attribut in the schema


return obj
}
Expand Down Expand Up @@ -129,11 +132,29 @@ 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"`
Copy link
Contributor

Choose a reason for hiding this comment

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

really need pointer ? without it we can remove GetNilIntPointer()
d.Get("disk_size")will give 0 when not set and that will not be push thanks to omitempty

}

func (cpdd *CloudProjectDatabaseDisk) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["size"] = cpdd.Size
obj["type"] = cpdd.Type
return obj
}

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 +184,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: helpers.GetNilIntPointer(d.Get("disk_size"))}
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 +211,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: helpers.GetNilIntPointer(d.Get("disk_size"))}
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