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

COD-3814 - Terraform add disable multi-AZ parameter #102

Merged
merged 1 commit into from
Mar 28, 2024
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
15 changes: 10 additions & 5 deletions docs/resources/operational_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ provider "cdp" {
}

resource "cdp_operational_database" "opdb" {
database_name = "<value>"
environment_name = "<value>"
database_name = "<value>"

scale_type = "MICRO" // valid options are "MICRO","LIGHT","HEAVY"
storage_type = "HDFS" // valid options are "CLOUD_WITH_EPHEMERAL","CLOUD","HDFS"
// scale_type = "MICRO" // valid options are "MICRO","LIGHT","HEAVY"
// storage_type = "HDFS" // valid options are "CLOUD_WITH_EPHEMERAL","CLOUD","HDFS"

disable_external_db = true
disable_multi_az = false
// num_edge_nodes = 1
}
```

Expand All @@ -57,10 +58,14 @@ resource "cdp_operational_database" "opdb" {

### Optional

- `disable_external_db` (Boolean) Disable external database creation or not
- `disable_external_db` (Boolean) Disable external database creation or not, it is only available in the BETA cdpcli
- `disable_multi_az` (Boolean) Disable deployment to multiple availability zones or not
- `java_version` (Number) Java version, it is only available in the BETA cdpcli
- `num_edge_nodes` (Number) Number of edge nodes
- `polling_options` (Attributes) Polling related configuration options that could specify various values that will be used during CDP resource creation. (see [below for nested schema](#nestedatt--polling_options))
- `scale_type` (String) Scale type, MICRO, LIGHT or HEAVY
- `storage_type` (String) Storage type for clusters, CLOUD_WITH_EPHEMERAL, CLOUD or HDFS
- `subnet_id` (String) ID of the subnet to deploy to

### Read-Only

Expand Down
9 changes: 5 additions & 4 deletions examples/resources/cdp_operational_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ provider "cdp" {
}

resource "cdp_operational_database" "opdb" {
database_name = "<value>"
environment_name = "<value>"
database_name = "<value>"

scale_type = "MICRO" // valid options are "MICRO","LIGHT","HEAVY"
storage_type = "HDFS" // valid options are "CLOUD_WITH_EPHEMERAL","CLOUD","HDFS"
// scale_type = "MICRO" // valid options are "MICRO","LIGHT","HEAVY"
// storage_type = "HDFS" // valid options are "CLOUD_WITH_EPHEMERAL","CLOUD","HDFS"

disable_external_db = true
disable_multi_az = false
// num_edge_nodes = 1
}
14 changes: 13 additions & 1 deletion resources/opdb/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package opdb
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"

opdbmodels "github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/opdb/models"
Expand All @@ -25,8 +26,19 @@ func fromModelToDatabaseRequest(model databaseResourceModel, ctx context.Context
req.EnvironmentName = model.Environment.ValueStringPointer()
req.ScaleType = opdbmodels.ScaleType(model.ScaleType.ValueString())
req.StorageType = opdbmodels.StorageType(model.StorageType.ValueString())
req.DisableExternalDB = !model.DisableExternalDB.IsNull() && model.DisableExternalDB.ValueBool()
req.DisableExternalDB = model.DisableExternalDB.ValueBool()

req.DisableMultiAz = model.DisableMultiAz.ValueBool()
req.SubnetID = model.SubnetID.ValueString()

req.JavaVersion = int64To32(model.JavaVersion)
req.NumEdgeNodes = int64To32(model.NumEdgeNodes)

tflog.Debug(ctx, fmt.Sprintf("Conversion from databaseResourceModel to CreateDatabaseRequest has finished with request: %+v.", req))
return &req
}

func int64To32(in types.Int64) int32 {
n64 := in.ValueInt64()
return int32(n64)
}
5 changes: 5 additions & 0 deletions resources/opdb/model_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ type databaseResourceModel struct {
StorageLocation types.String `tfsdk:"storage_location"`

PollingOptions *utils.PollingOptions `tfsdk:"polling_options"`

DisableMultiAz types.Bool `tfsdk:"disable_multi_az"`
NumEdgeNodes types.Int64 `tfsdk:"num_edge_nodes"`
JavaVersion types.Int64 `tfsdk:"java_version"`
SubnetID types.String `tfsdk:"subnet_id"`
}
2 changes: 2 additions & 0 deletions resources/opdb/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func getCommonDatabaseDetails(data *databaseResourceModel, databaseDetails *opdb

data.ScaleType = types.StringValue(string(databaseDetails.ScaleType))
data.StorageLocation = types.StringValue(databaseDetails.StorageLocation)

data.NumEdgeNodes = types.Int64Value(int64(databaseDetails.DbEdgeNodeCount))
}

func (r *databaseResource) Update(ctx context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) {
Expand Down
26 changes: 25 additions & 1 deletion resources/opdb/schema_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"

"github.com/cloudera/terraform-provider-cdp/utils"
)

Expand All @@ -33,15 +36,36 @@ func (r *databaseResource) Schema(_ context.Context, _ resource.SchemaRequest, r
"scale_type": schema.StringAttribute{
MarkdownDescription: "Scale type, MICRO, LIGHT or HEAVY",
Optional: true,
Computed: true,
Default: stringdefault.StaticString("LIGHT"),
},
"storage_type": schema.StringAttribute{
MarkdownDescription: "Storage type for clusters, CLOUD_WITH_EPHEMERAL, CLOUD or HDFS",
Optional: true,
},
"disable_external_db": schema.BoolAttribute{
MarkdownDescription: "Disable external database creation or not",
MarkdownDescription: "Disable external database creation or not, it is only available in the BETA cdpcli",
Optional: true,
},
"disable_multi_az": schema.BoolAttribute{
MarkdownDescription: "Disable deployment to multiple availability zones or not",
Optional: true,
},
"subnet_id": schema.StringAttribute{
MarkdownDescription: "ID of the subnet to deploy to",
Optional: true,
},
"num_edge_nodes": schema.Int64Attribute{
MarkdownDescription: "Number of edge nodes",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
},
"java_version": schema.Int64Attribute{
MarkdownDescription: "Java version, it is only available in the BETA cdpcli",
Optional: true,
},

"storage_location": schema.StringAttribute{
MarkdownDescription: "Storage Location for OPDB",
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion resources/opdb/schema_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSchemaContainsScaleType(t *testing.T) {
test := TestCaseStructure{
name: "scale_type should exist",
field: "scale_type",
computed: false,
computed: true,
shouldBeRequired: false,
}

Expand Down
Loading