Skip to content

Commit

Permalink
COD-3814 - Terraform add disable multi-AZ parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Antal committed Mar 27, 2024
1 parent c2f4861 commit c4f2dd1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
11 changes: 8 additions & 3 deletions docs/resources/operational_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ resource "cdp_operational_database" "opdb" {
database_name = "<value>"
environment_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 @@ -58,9 +59,13 @@ resource "cdp_operational_database" "opdb" {
### Optional

- `disable_external_db` (Boolean) Disable external database creation or not
- `disable_multi_az` (Boolean) Disable deployment to multiple availability zones or not
- `java_version` (Number) Java version
- `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
7 changes: 4 additions & 3 deletions examples/resources/cdp_operational_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ resource "cdp_operational_database" "opdb" {
database_name = "<value>"
environment_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
}
12 changes: 12 additions & 0 deletions 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 @@ -27,6 +28,17 @@ func fromModelToDatabaseRequest(model databaseResourceModel, ctx context.Context
req.StorageType = opdbmodels.StorageType(model.StorageType.ValueString())
req.DisableExternalDB = !model.DisableExternalDB.IsNull() && model.DisableExternalDB.ValueBool()

req.DisableMultiAz = !model.DisableMultiAz.IsNull() && 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
24 changes: 24 additions & 0 deletions 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,6 +36,8 @@ 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",
Expand All @@ -42,6 +47,25 @@ func (r *databaseResource) Schema(_ context.Context, _ resource.SchemaRequest, r
MarkdownDescription: "Disable external database creation or not",
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",
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

0 comments on commit c4f2dd1

Please sign in to comment.