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

AV-90385 Azure cluster updates #240

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions examples/cluster/azure/create_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ resource "couchbase-capella_cluster" "new_cluster" {
ram = var.compute.ram
}
disk = {
storage = var.disk.storage
type = var.disk.type
iops = var.disk.iops
autoexpansion = var.disk.autoexpansion
}
}
Expand Down
32 changes: 32 additions & 0 deletions examples/cluster/azure/terraform.template.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,35 @@ support = {
plan = "basic"
timezone = "PT"
}


# Example for Ultra disk type Azure Cluster:
PaulomeeCb marked this conversation as resolved.
Show resolved Hide resolved

# cloud_provider = {
# name = "azure",
# region = "eastus"
# }
# cluster = {
# name = "TF Azure Ultra"
# cidr = "10.10.0.0/23"
# node_count = 3
# couchbase_services = ["data", "index", "query", "search"]
# availability_zone = "single"
# }
#
# compute = {
# cpu = 4
# ram = 16
# }
#
# disk = {
# type = "Ultra"
# storage = 128
# iops = 5000
# autoexpansion = true
# }
#
# support = {
# plan = "developer pro"
# timezone = "PT"
# }
2 changes: 1 addition & 1 deletion examples/cluster/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "disk" {
description = "All nodes' disk configuration"

type = object({
size = optional(number)
storage = optional(number)
PaulomeeCb marked this conversation as resolved.
Show resolved Hide resolved
type = string
iops = optional(number)
autoexpansion = optional(bool)
Expand Down
33 changes: 17 additions & 16 deletions internal/resources/acceptance_tests/cluster_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,16 @@ func TestAccClusterResourceAzure(t *testing.T) {
resource.TestCheckResourceAttr(resourceReference, "cloud_provider.cidr", cidr),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.compute.cpu", "4"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.compute.ram", "16"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.storage", "1024"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.type", "Ultra"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "17000"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.type", "P6"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "240"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.num_of_nodes", "3"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.#", "3"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.0", "data"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.1", "index"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.2", "query"),
resource.TestCheckResourceAttr(resourceReference, "availability.type", "multi"),
resource.TestCheckResourceAttr(resourceReference, "support.plan", "developer pro"),
resource.TestCheckResourceAttr(resourceReference, "support.timezone", "PT"),
resource.TestCheckResourceAttr(resourceReference, "support.timezone", "GMT"),
resource.TestCheckResourceAttr(resourceReference, "enable_private_dns_resolution", "false"),
),
},
Expand All @@ -276,7 +275,7 @@ func TestAccClusterResourceAzure(t *testing.T) {
},

{
Config: testAccClusterResourceConfigAzureUpdateToDiskTypeP6(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Config: testAccClusterResourceConfigAzureUpdateTimezone(acctest.Cfg, resourceName, projectResourceName, projectResourceReference, cidr),
Check: resource.ComposeAggregateTestCheckFunc(
testAccExistsClusterResource(resourceReference),
resource.TestCheckResourceAttr(resourceReference, "name", "Terraform Acceptance Test Cluster"),
Expand All @@ -286,9 +285,9 @@ func TestAccClusterResourceAzure(t *testing.T) {
resource.TestCheckResourceAttr(resourceReference, "cloud_provider.cidr", cidr),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.compute.cpu", "4"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.compute.ram", "32"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.storage", "64"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.type", "P6"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "240"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.storage", "1024"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.type", "Ultra"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "17000"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.num_of_nodes", "3"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.#", "3"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.0", "data"),
Expand Down Expand Up @@ -338,7 +337,7 @@ func TestAccClusterResourceAzure(t *testing.T) {
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.compute.ram", "16"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.storage", "1024"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.type", "Ultra"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "2000"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.node.disk.iops", "17000"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.num_of_nodes", "3"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.#", "1"),
resource.TestCheckResourceAttr(resourceReference, "service_groups.0.services.0", "data"),
Expand Down Expand Up @@ -1006,9 +1005,9 @@ resource "couchbase-capella_cluster" "%[2]s" {
ram = 16
}
disk = {
storage = 1024,
type = "Ultra"
iops = 17000
type = "P6"
autoexpansion = true

}
}
num_of_nodes = 3
Expand All @@ -1020,7 +1019,7 @@ resource "couchbase-capella_cluster" "%[2]s" {
}
support = {
plan = "developer pro"
timezone = "PT"
timezone = "GMT"
}
}
`, cfg, resourceName, projectResourceName, projectResourceReference, cidr)
Expand Down Expand Up @@ -1076,7 +1075,7 @@ resource "couchbase-capella_cluster" "%[2]s" {

// testAccClusterResourceConfigAzureUpdateToDiskTypeP6 generates a Terraform configuration string for testing an acceptance test scenario
// where a cluster resource is updated to change the disk type to "P6".
func testAccClusterResourceConfigAzureUpdateToDiskTypeP6(cfg, resourceName, projectResourceName, projectResourceReference, cidr string) string {
func testAccClusterResourceConfigAzureUpdateTimezone(cfg, resourceName, projectResourceName, projectResourceReference, cidr string) string {
return fmt.Sprintf(`
%[1]s

Expand Down Expand Up @@ -1105,7 +1104,9 @@ resource "couchbase-capella_cluster" "%[2]s" {
ram = 32
}
disk = {
type = "P6"
storage = 1024,
type = "Ultra"
iops = 17000
}
}
num_of_nodes = 3
Expand Down Expand Up @@ -1209,7 +1210,7 @@ resource "couchbase-capella_cluster" "%[2]s" {
disk = {
storage = 1024,
type = "Ultra"
iops = 2000
iops = 17000
}
}
num_of_nodes = 3
Expand Down
46 changes: 39 additions & 7 deletions internal/resources/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ func (c *Cluster) Create(ctx context.Context, req resource.CreateRequest, resp *
if clusterapi.AreEqual(plan.ServiceGroups[i].Services, serviceGroup.Services) {
refreshedState.ServiceGroups[i].Services = plan.ServiceGroups[i].Services
}

// This is for the case when for Azure clusters - Premium disk types, if the user provides the storage and iops values (these values are ignored), then put the value provided in state file,
// as otherwise there will be a type mismatch with the actual value - i.e. the default values for premium disks.
if refreshedState.CloudProvider.Type == types.StringValue("Azure") {
if refreshedState.ServiceGroups[i].Node.Disk.Type != types.StringValue("Ultra") {
refreshedState.ServiceGroups[i].Node.Disk.Storage = plan.ServiceGroups[i].Node.Disk.Storage
refreshedState.ServiceGroups[i].Node.Disk.IOPS = plan.ServiceGroups[i].Node.Disk.IOPS
}
}

}

// Set state to fully populated data
Expand Down Expand Up @@ -423,6 +433,16 @@ func (c *Cluster) Update(ctx context.Context, req resource.UpdateRequest, resp *
if clusterapi.AreEqual(plan.ServiceGroups[i].Services, serviceGroup.Services) {
currentState.ServiceGroups[i].Services = plan.ServiceGroups[i].Services
}

// for Azure clusters - Premium disk types, if the user provides the storage and iops values (these values are ignored), then put the value provided in state file,
// as otherwise there will be a type mismatch with the actual value - i.e. the default values for premium disks.
if currentState.CloudProvider.Type == types.StringValue("Azure") {
PaulomeeCb marked this conversation as resolved.
Show resolved Hide resolved
if currentState.ServiceGroups[i].Node.Disk.Type != types.StringValue("Ultra") {
currentState.ServiceGroups[i].Node.Disk.Storage = plan.ServiceGroups[i].Node.Disk.Storage
currentState.ServiceGroups[i].Node.Disk.IOPS = plan.ServiceGroups[i].Node.Disk.IOPS
}
}

}

// Set state to fully populated data
Expand Down Expand Up @@ -655,14 +675,17 @@ func (c *Cluster) morphToApiServiceGroups(plan providerschema.Cluster) ([]cluste
Type: clusterapi.DiskAzureType(serviceGroup.Node.Disk.Type.ValueString()),
}

if serviceGroup.Node != nil && !serviceGroup.Node.Disk.Storage.IsNull() && !serviceGroup.Node.Disk.Storage.IsUnknown() {
storage := int(serviceGroup.Node.Disk.Storage.ValueInt64())
diskAzure.Storage = &storage
}
// only allow setting storage and iops values for Ultra type disks, not for Premium type disks
if diskAzure.Type == "Ultra" {
if serviceGroup.Node != nil && !serviceGroup.Node.Disk.Storage.IsNull() && !serviceGroup.Node.Disk.Storage.IsUnknown() {
storage := int(serviceGroup.Node.Disk.Storage.ValueInt64())
diskAzure.Storage = &storage
}

if serviceGroup.Node != nil && !serviceGroup.Node.Disk.IOPS.IsNull() && !serviceGroup.Node.Disk.Storage.IsUnknown() {
iops := int(serviceGroup.Node.Disk.IOPS.ValueInt64())
diskAzure.Iops = &iops
if serviceGroup.Node != nil && !serviceGroup.Node.Disk.IOPS.IsNull() && !serviceGroup.Node.Disk.Storage.IsUnknown() {
iops := int(serviceGroup.Node.Disk.IOPS.ValueInt64())
diskAzure.Iops = &iops
}
}

if serviceGroup.Node != nil && !serviceGroup.Node.Disk.Autoexpansion.IsNull() {
Expand All @@ -673,6 +696,15 @@ func (c *Cluster) morphToApiServiceGroups(plan providerschema.Cluster) ([]cluste
if err := node.FromDiskAzure(diskAzure); err != nil {
return nil, fmt.Errorf("%s: %w", errors.ErrConvertingServiceGroups, err)
}

//fmt.Printf("************************PAULOMEE Create/Update DISKAzure %#v \n", diskAzure)
//b, _ := json.Marshal(diskAzure)
//fmt.Print(string(b))
//
//fmt.Printf("************************PAULOMEE Create/Update node %#v \n", node)
//b, _ = json.Marshal(node)
//fmt.Print(string(b))

PaulomeeCb marked this conversation as resolved.
Show resolved Hide resolved
newServiceGroup.Node.Disk = node.Disk

case string(clusterapi.Gcp):
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ClusterSchema() schema.Schema {
},
"disk": schema.SingleNestedAttribute{
Description: "The 'storage' and 'IOPS' fields are required for AWS. " +
"For Azure, only the 'disktype' field is required, and for Ultra, you can provide all three fields. " +
"For Azure, only the 'disktype' field is required, and for Ultra disk type, you can provide all 3 - storage, iops and autoexpansion fields. For Premium type, you can only provide the autoexpansion field, others can't be set." +
"In the case of GCP, only 'pd ssd' disk type is available, and you cannot set the 'IOPS' field.",
Required: true,
Attributes: map[string]schema.Attribute{
Expand Down
Loading