diff --git a/examples/appservice/README.md b/examples/appservice/README.md index 0a1dbfca..a4d5852b 100644 --- a/examples/appservice/README.md +++ b/examples/appservice/README.md @@ -495,7 +495,7 @@ The third ID is the project ID i.e. the ID of the project to which the cluster b The fourth ID is the organization ID i.e. the ID of the organization to which the project belongs. ## UPDATE -### Let us edit the terraform.tfvars file to change the cluster configuration settings. +### Let us edit the terraform.tfvars file to change the app service configuration settings. Command: `terraform apply -var-file=terraform.template.tfvars` diff --git a/examples/backup_schedule/README.md b/examples/backup_schedule/README.md new file mode 100644 index 00000000..10e3c5a4 --- /dev/null +++ b/examples/backup_schedule/README.md @@ -0,0 +1,433 @@ +# Capella Backup Schedule Example + +This example shows how to create and manage Backup Schedules in Capella. + +This creates a new backup schedule in the selected Capella cluster. It uses the organization ID, project ID, cluster ID and bucket ID to do so. + +To run, configure your Couchbase Capella provider as described in README in the root of this project. + +# Example Walkthrough + +In this example, we are going to do the following. + +1. CREATE: Create a new backup schedule entry in an existing Capella cluster as stated in the `create_backup_schedule.tf` file. +2. UPDATE: Update the backup schedule configuration using Terraform. +3. IMPORT: Import a backup schedule that exists in Capella but not in the terraform state file. +4. DELETE: Delete the newly created backup schedule from Capella. + +If you wish to use the `terraform.template.tfvars` file - Make sure you copy the file to `terraform.tfvars` and update the values of the variables as per the correct organization access. + +## CREATE & READ +### View the plan for the resources that Terraform will create + +Command: `terraform plan` + +Sample Output: +``` +terraform plan +╷ +│ Warning: Provider development overrides are in effect +│ +│ The following provider development overrides are set in the CLI configuration: +│ - hashicorp.com/couchabasecloud/capella in /Users/talina.shrotriya/workspace/terraform-provider-capella +│ +│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published +│ releases. +╵ + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + + # capella_backup_schedule.new_backup_schedule will be created + + resource "capella_backup_schedule" "new_backup_schedule" { + + bucket_id = "dGVzdC1idWNrZXQ=" + + cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + + organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + + project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" + + type = "weekly" + + weekly_schedule = { + + cost_optimized_retention = false + + day_of_week = "Monday" + + incremental_every = 6 + + retention_time = "30days" + + start_at = 10 + } + } + +Plan: 1 to add, 0 to change, 0 to destroy. + +Changes to Outputs: + + new_backup_schedule = { + + bucket_id = "dGVzdC1idWNrZXQ=" + + cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + + organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + + project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" + + type = "weekly" + + weekly_schedule = { + + cost_optimized_retention = false + + day_of_week = "Monday" + + incremental_every = 6 + + retention_time = "30days" + + start_at = 10 + } + } +``` + +### Apply the Plan, in order to create a new Backup Schedule entry + +Command: `terraform apply` + +Sample Output: +``` +terraform apply +╷ +│ Warning: Provider development overrides are in effect +│ +│ The following provider development overrides are set in the CLI configuration: +│ - hashicorp.com/couchabasecloud/capella in /Users/talina.shrotriya/workspace/terraform-provider-capella +│ +│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published +│ releases. +╵ + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + + # capella_backup_schedule.new_backup_schedule will be created + + resource "capella_backup_schedule" "new_backup_schedule" { + + bucket_id = "dGVzdC1idWNrZXQ=" + + cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + + organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + + project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" + + type = "weekly" + + weekly_schedule = { + + cost_optimized_retention = false + + day_of_week = "Monday" + + incremental_every = 6 + + retention_time = "30days" + + start_at = 10 + } + } + +Plan: 1 to add, 0 to change, 0 to destroy. + +Changes to Outputs: + + new_backup_schedule = { + + bucket_id = "dGVzdC1idWNrZXQ=" + + cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + + organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + + project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" + + type = "weekly" + + weekly_schedule = { + + cost_optimized_retention = false + + day_of_week = "Monday" + + incremental_every = 6 + + retention_time = "30days" + + start_at = 10 + } + } + +Do you want to perform these actions? + Terraform will perform the actions described above. + Only 'yes' will be accepted to approve. + + Enter a value: yes + +capella_backup_schedule.new_backup_schedule: Creating... +capella_backup_schedule.new_backup_schedule: Creation complete after 1s + +Apply complete! Resources: 1 added, 0 changed, 0 destroyed. + +Outputs: + +new_backup_schedule = { + "bucket_id" = "dGVzdC1idWNrZXQ=" + "cluster_id" = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + "organization_id" = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + "project_id" = "53b0e002-eb11-4317-9a53-6a781b29960e" + "type" = "weekly" + "weekly_schedule" = { + "cost_optimized_retention" = false + "day_of_week" = "Monday" + "incremental_every" = 6 + "retention_time" = "30days" + "start_at" = 10 + } +} +``` + +### Note the Bucket ID of the new Backup Schedule required for import. +Command: `terraform output new_backup_schedule` + +Sample Output: +``` +terraform output new_backup_schedule +{ + "bucket_id" = "dGVzdC1idWNrZXQ=" + "cluster_id" = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + "organization_id" = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + "project_id" = "53b0e002-eb11-4317-9a53-6a781b29960e" + "type" = "weekly" + "weekly_schedule" = { + "cost_optimized_retention" = false + "day_of_week" = "Monday" + "incremental_every" = 6 + "retention_time" = "30days" + "start_at" = 10 + } +} +``` +In this case, the bucket ID is `dGVzdC1idWNrZXQ=` + +### List the resources that are present in the Terraform State file. + +Command: `terraform state list` + +Sample Output: +``` +terraform state list +capella_backup_schedule.new_backup_schedule +``` + +## IMPORT +### Remove the resource `new_backup_schedule` from the Terraform State file + +Command: `terraform state rm capella_backup_schedule.new_backup_schedule` + +Sample Output: +``` +terraform state rm capella_backup_schedule.new_backup_schedule +Removed capella_backup_schedule.new_backup_schedule +Successfully removed 1 resource instance(s). +``` +Please note, this command will only remove the resource from the Terraform State file, but in reality, the resource exists in Capella. + +### Now, let's import the resource in Terraform + +Command: `terraform import capella_backup.new_backup id=,cluster_id=,project_id=,organization_id=` + +In this case, the complete command is: +`terraform import capella_backup_schedule.new_backup_schedule bucket_id=dGVzdC1idWNrZXQ=,cluster_id=4f728ab7-dbbc-45a2-9789-ee172f09851e,project_id=53b0e002-eb11-4317-9a53-6a781b29960e,organization_id=7a99d00c-f55b-4b39-bc72-1b4cc68ba894` + +Sample Output: +``` +terraform import capella_backup_schedule.new_backup_schedule bucket_id=dGVzdC1idWNrZXQ=,cluster_id=4f728ab7-dbbc-45a2-9789-ee172f09851e,project_id=53b0e002-eb11-4317-9a53-6a781b29960e,organization_id=7a99d00c-f55b-4b39-bc72-1b4cc68ba894 +capella_backup_schedule.new_backup_schedule: Importing from ID "bucket_id=dGVzdC1idWNrZXQ=,cluster_id=4f728ab7-dbbc-45a2-9789-ee172f09851e,project_id=53b0e002-eb11-4317-9a53-6a781b29960e,organization_id=7a99d00c-f55b-4b39-bc72-1b4cc68ba894"... +capella_backup_schedule.new_backup_schedule: Import prepared! + Prepared capella_backup_schedule for import +capella_backup_schedule.new_backup_schedule: Refreshing state... + +Import successful! + +The resources that were imported are shown above. These resources are now in +your Terraform state and will henceforth be managed by Terraform. +``` + +Here, we pass the IDs as a single comma-separated string. +The first ID in the string is the bucket ID i.e. the ID of the bucket to which the backup schedule belongs. +The second ID is the cluster ID i.e. the ID of the cluster to which bucket belongs. +The third ID is the project ID i.e. the ID of the project to which the cluster belongs. +The fourth ID is the organization ID i.e. the ID of the organization to which the project belongs. + +## UPDATE +### Let us edit terraform.tfvars file to change the backup schedule configuration settings. + +Command: `terraform plan` + +Sample Output: + +``` +terraform plan +╷ +│ Warning: Provider development overrides are in effect +│ +│ The following provider development overrides are set in the CLI configuration: +│ - hashicorp.com/couchabasecloud/capella in /Users/talina.shrotriya/workspace/terraform-provider-capella +│ +│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published +│ releases. +╵ +capella_backup_schedule.new_backup_schedule: Refreshing state... + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + ~ update in-place + +Terraform will perform the following actions: + + # capella_backup_schedule.new_backup_schedule will be updated in-place + ~ resource "capella_backup_schedule" "new_backup_schedule" { + ~ weekly_schedule = { + ~ cost_optimized_retention = false -> true + ~ day_of_week = "Monday" -> "Friday" + ~ incremental_every = 6 -> 4 + ~ retention_time = "30days" -> "60days" + ~ start_at = 10 -> 7 + } + # (5 unchanged attributes hidden) + } + +Plan: 0 to add, 1 to change, 0 to destroy. + +Changes to Outputs: + ~ new_backup_schedule = { + ~ weekly_schedule = { + ~ cost_optimized_retention = false -> true + ~ day_of_week = "Monday" -> "Friday" + ~ incremental_every = 6 -> 4 + ~ retention_time = "30days" -> "60days" + ~ start_at = 10 -> 7 + } + # (5 unchanged attributes hidden) + } +``` + +command: `terrafom apply` + +Sample Output: + +``` +$ terraform apply +╷ +│ Warning: Provider development overrides are in effect +│ +│ The following provider development overrides are set in the CLI configuration: +│ - hashicorp.com/couchabasecloud/capella in /Users/talina.shrotriya/workspace/terraform-provider-capella +│ +│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published +│ releases. +╵ +capella_backup_schedule.new_backup_schedule: Refreshing state... + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + ~ update in-place + +Terraform will perform the following actions: + + # capella_backup_schedule.new_backup_schedule will be updated in-place + ~ resource "capella_backup_schedule" "new_backup_schedule" { + ~ weekly_schedule = { + ~ cost_optimized_retention = false -> true + ~ day_of_week = "Monday" -> "Friday" + ~ incremental_every = 6 -> 4 + ~ retention_time = "30days" -> "60days" + ~ start_at = 10 -> 7 + } + # (5 unchanged attributes hidden) + } + +Plan: 0 to add, 1 to change, 0 to destroy. + +Changes to Outputs: + ~ new_backup_schedule = { + ~ weekly_schedule = { + ~ cost_optimized_retention = false -> true + ~ day_of_week = "Monday" -> "Friday" + ~ incremental_every = 6 -> 4 + ~ retention_time = "30days" -> "60days" + ~ start_at = 10 -> 7 + } + # (5 unchanged attributes hidden) + } + +Do you want to perform these actions? + Terraform will perform the actions described above. + Only 'yes' will be accepted to approve. + + Enter a value: yes + +capella_backup_schedule.new_backup_schedule: Modifying... +capella_backup_schedule.new_backup_schedule: Modifications complete after 1s + +Apply complete! Resources: 0 added, 1 changed, 0 destroyed. + +Outputs: + +new_backup_schedule = { + "bucket_id" = "dGVzdC1idWNrZXQ=" + "cluster_id" = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + "organization_id" = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + "project_id" = "53b0e002-eb11-4317-9a53-6a781b29960e" + "type" = "weekly" + "weekly_schedule" = { + "cost_optimized_retention" = true + "day_of_week" = "Friday" + "incremental_every" = 4 + "retention_time" = "60days" + "start_at" = 7 + } +} +``` + +## DESTROY +### Finally, destroy the resources created by Terraform + +Command: `terraform destroy` + +Sample Output: +``` +terraform destroy +╷ +│ Warning: Provider development overrides are in effect +│ +│ The following provider development overrides are set in the CLI configuration: +│ - hashicorp.com/couchabasecloud/capella in /Users/talina.shrotriya/workspace/terraform-provider-capella +│ +│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published +│ releases. +╵ +capella_backup_schedule.new_backup_schedule: Refreshing state... + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + - destroy + +Terraform will perform the following actions: + + # capella_backup_schedule.new_backup_schedule will be destroyed + - resource "capella_backup_schedule" "new_backup_schedule" { + - bucket_id = "dGVzdC1idWNrZXQ=" -> null + - cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" -> null + - organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" -> null + - project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" -> null + - type = "weekly" -> null + - weekly_schedule = { + - cost_optimized_retention = true -> null + - day_of_week = "Friday" -> null + - incremental_every = 4 -> null + - retention_time = "60days" -> null + - start_at = 7 -> null + } -> null + } + +Plan: 0 to add, 0 to change, 1 to destroy. + +Changes to Outputs: + - new_backup_schedule = { + - bucket_id = "dGVzdC1idWNrZXQ=" + - cluster_id = "4f728ab7-dbbc-45a2-9789-ee172f09851e" + - organization_id = "7a99d00c-f55b-4b39-bc72-1b4cc68ba894" + - project_id = "53b0e002-eb11-4317-9a53-6a781b29960e" + - type = "weekly" + - weekly_schedule = { + - cost_optimized_retention = true + - day_of_week = "Friday" + - incremental_every = 4 + - retention_time = "60days" + - start_at = 7 + } + } -> null + +Do you really want to destroy all resources? + Terraform will destroy all your managed infrastructure, as shown above. + There is no undo. Only 'yes' will be accepted to confirm. + + Enter a value: yes + +capella_backup_schedule.new_backup_schedule: Destroying... +capella_backup_schedule.new_backup_schedule: Destruction complete after 1s + +Destroy complete! Resources: 1 destroyed. +``` diff --git a/examples/database_credential/README.md b/examples/database_credential/README.md index 8aa4e596..81d27b95 100644 --- a/examples/database_credential/README.md +++ b/examples/database_credential/README.md @@ -351,7 +351,7 @@ new_database_credential = ``` ## UPDATE -### Let us edit the terraform.tfvars file to change the bucket configuration settings. +### Let us edit the terraform.tfvars file to change the Database Credential configuration settings. Command: `terraform apply -var 'access=[{privileges=["data_reader"]}]'` diff --git a/internal/resources/acceptance_tests/appservice_acceptance_test.go b/internal/resources/acceptance_tests/appservice_acceptance_test.go new file mode 100644 index 00000000..7e161171 --- /dev/null +++ b/internal/resources/acceptance_tests/appservice_acceptance_test.go @@ -0,0 +1,132 @@ +package acceptance_tests + +import ( + "fmt" + "testing" + + cfg "terraform-provider-capella/internal/testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestAppServiceResource(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read testing + { + Config: testAccAppServiceResourceConfig(cfg.Cfg), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "name", "test-terraform-app-service"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "description", "description"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.cpu", "2"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.ram", "4"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "nodes", "2"), + ), + }, + //// ImportState testing + { + ResourceName: "capella_app_service.new_app_service", + ImportStateIdFunc: generateAppServiceImportId, + ImportState: true, + ImportStateVerify: true, + }, + // Update and Read testing + { + Config: testAccAppServiceResourceConfigUpdate(cfg.Cfg), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "name", "test-terraform-app-service"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "description", "description"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.cpu", "2"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.ram", "4"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "nodes", "3"), + ), + }, + { + Config: testAccAppServiceResourceConfigUpdateWithIfMatch(cfg.Cfg), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "name", "test-terraform-app-service"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "description", "description"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.cpu", "4"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "compute.ram", "8"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "nodes", "2"), + resource.TestCheckResourceAttr("capella_app_service.new_app_service", "if_match", "2"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + +func testAccAppServiceResourceConfig(cfg string) string { + return fmt.Sprintf(` +%[1]s + +resource "capella_app_service" "new_app_service" { + organization_id = var.organization_id + project_id = var.project_id + cluster_id = var.cluster_id + name = "test-terraform-app-service" + description = "description" + compute = { + cpu = 2 + ram = 4 +} +} +`, cfg) +} + +func testAccAppServiceResourceConfigUpdate(cfg string) string { + return fmt.Sprintf(` +%[1]s + +resource "capella_app_service" "new_app_service" { + organization_id = var.organization_id + project_id = var.project_id + cluster_id = var.cluster_id + name = "test-terraform-app-service" + description = "description" + compute = { + cpu = 2 + ram = 4 + } + nodes = 3 +} +`, cfg) +} + +func testAccAppServiceResourceConfigUpdateWithIfMatch(cfg string) string { + return fmt.Sprintf(` +%[1]s + +resource "capella_app_service" "new_app_service" { + organization_id = var.organization_id + project_id = var.project_id + cluster_id = var.cluster_id + name = "test-terraform-app-service" + description = "description" + if_match = 2 + compute = { + cpu = 4 + ram = 8 + } + nodes = 2 +} +`, cfg) +} + +func generateAppServiceImportId(state *terraform.State) (string, error) { + resourceName := "capella_app_service.new_app_service" + var rawState map[string]string + for _, m := range state.Modules { + if len(m.Resources) > 0 { + if v, ok := m.Resources[resourceName]; ok { + rawState = v.Primary.Attributes + } + } + } + fmt.Printf("raw state %s", rawState) + return fmt.Sprintf("id=%s,cluster_id=%s,project_id=%s,organization_id=%s", rawState["id"], rawState["cluster_id"], rawState["project_id"], rawState["organization_id"]), nil +} diff --git a/internal/resources/appservice.go b/internal/resources/appservice.go index 245a3002..961448ab 100644 --- a/internal/resources/appservice.go +++ b/internal/resources/appservice.go @@ -183,6 +183,10 @@ func (a *AppService) Read(ctx context.Context, req resource.ReadRequest, resp *r return } + if !state.IfMatch.IsUnknown() && !state.IfMatch.IsNull() { + refreshedState.IfMatch = state.IfMatch + } + // Set refreshed state diags = resp.State.Set(ctx, &refreshedState) resp.Diagnostics.Append(diags...) diff --git a/internal/resources/attributes.go b/internal/resources/attributes.go index 75d0dbe4..d7732171 100644 --- a/internal/resources/attributes.go +++ b/internal/resources/attributes.go @@ -2,11 +2,14 @@ package resources import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/float64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -50,6 +53,13 @@ func stringAttribute(fields ...string) *schema.StringAttribute { return &attribute } +// stringDefaultAttribute sets the default values for a string field and returns the string attribute +func stringDefaultAttribute(defaultValue string, fields ...string) *schema.StringAttribute { + attribute := stringAttribute(fields...) + attribute.Default = stringdefault.StaticString(defaultValue) + return attribute +} + // boolAttribute is a variadic function which sets the requested fields // in a bool attribute to true and then returns the string attribute. func boolAttribute(fields ...string) *schema.BoolAttribute { @@ -75,6 +85,13 @@ func boolAttribute(fields ...string) *schema.BoolAttribute { return &attribute } +// boolDefaultAttribute sets the default values for a boolean field and returns the bool attribute +func boolDefaultAttribute(defaultValue bool, fields ...string) *schema.BoolAttribute { + attribute := boolAttribute(fields...) + attribute.Default = booldefault.StaticBool(defaultValue) + return attribute +} + // int64Attribute is a variadic function which sets the requested fields // in an Int64 attribute to true and then returns the string attribute. func int64Attribute(fields ...string) *schema.Int64Attribute { @@ -105,6 +122,13 @@ func int64Attribute(fields ...string) *schema.Int64Attribute { return &attribute } +// int64DefaultAttribute sets the default values for an int field and returns the int64 attribute +func int64DefaultAttribute(defaultValue int64, fields ...string) *schema.Int64Attribute { + attribute := int64Attribute(fields...) + attribute.Default = int64default.StaticInt64(defaultValue) + return attribute +} + // numberAttribute is a variadic function which sets the requested fields // in an number attribute to true and then returns the string attribute. func numberAttribute(fields ...string) *schema.NumberAttribute { diff --git a/internal/resources/bucket_schema.go b/internal/resources/bucket_schema.go index 6c599ed7..e346db4a 100644 --- a/internal/resources/bucket_schema.go +++ b/internal/resources/bucket_schema.go @@ -15,19 +15,19 @@ func BucketSchema() schema.Schema { stringplanmodifier.UseStateForUnknown(), }, }, + "name": stringAttribute(required, requiresReplace), "organization_id": stringAttribute(required), "project_id": stringAttribute(required), "cluster_id": stringAttribute(required), - "name": stringAttribute(required, requiresReplace), - "type": stringAttribute(optional, computed), - "storage_backend": stringAttribute(optional, computed), - "memory_allocation_in_mb": int64Attribute(optional, computed), - "bucket_conflict_resolution": stringAttribute(optional, computed), - "durability_level": stringAttribute(optional, computed), - "replicas": int64Attribute(optional, computed), - "flush": boolAttribute(optional, computed), - "time_to_live_in_seconds": int64Attribute(optional, computed), - "eviction_policy": stringAttribute(computed, optional), + "type": stringDefaultAttribute("couchbase", optional, computed, requiresReplace), + "storage_backend": stringAttribute(optional, computed, requiresReplace), + "memory_allocation_in_mb": int64DefaultAttribute(100, optional, computed), + "bucket_conflict_resolution": stringDefaultAttribute("seqno", optional, computed, requiresReplace), + "durability_level": stringDefaultAttribute("none", optional, computed), + "replicas": int64DefaultAttribute(1, optional, computed), + "flush": boolDefaultAttribute(false, optional, computed), + "time_to_live_in_seconds": int64DefaultAttribute(0, optional, computed), + "eviction_policy": stringAttribute(optional, computed, requiresReplace), "stats": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ diff --git a/internal/testing/config.go b/internal/testing/config.go index 5570c5c3..22333be4 100644 --- a/internal/testing/config.go +++ b/internal/testing/config.go @@ -9,10 +9,19 @@ variable "organization_id" { description = "Capella Organization ID" } +variable "project_id" { + description = "Capella Project ID" +} + +variable "cluster_id" { + description = "Capella Project ID" +} + variable "auth_token" { description = "Authentication API Key" sensitive = true } + provider "capella" { host = var.host authentication_token = var.auth_token