diff --git a/examples/allowlist/create_allowlist.tf b/examples/allowlist/create_allowlist.tf index 5f9ca0a0..c9158811 100644 --- a/examples/allowlist/create_allowlist.tf +++ b/examples/allowlist/create_allowlist.tf @@ -10,7 +10,7 @@ resource "capella_allowlist" "new_allowlist" { organization_id = var.organization_id project_id = var.project_id cluster_id = var.cluster_id - cidr = var.cidr - comment = var.comment - expires_at = var.expires_at + cidr = var.allowlist.cidr + comment = var.allowlist.comment + expires_at = var.allowlist.expires_at } diff --git a/examples/allowlist/terraform.template.tfvars b/examples/allowlist/terraform.template.tfvars index 9160dcbb..58e54090 100644 --- a/examples/allowlist/terraform.template.tfvars +++ b/examples/allowlist/terraform.template.tfvars @@ -3,5 +3,9 @@ organization_id = "" project_id = "" cluster_id = "" host = "https://cloudapi.cloud.couchbase.com" -cidr = "10.0.0.0/16" -expires_at = "2023-11-30T23:59:59.465Z" \ No newline at end of file + +allowlist = { + cidr = "10.0.0.0/16" + comment = "Allow access from a public IP" + expires_at = "2023-12-30T23:59:59.465Z" +} \ No newline at end of file diff --git a/examples/allowlist/variables.tf b/examples/allowlist/variables.tf index c2a02a36..6b3a8d97 100644 --- a/examples/allowlist/variables.tf +++ b/examples/allowlist/variables.tf @@ -19,14 +19,12 @@ variable "auth_token" { sensitive = true } -variable "comment" { - description = "comment describing the allowlist details" -} - -variable "cidr" { - description = "CIDR that will have access to the cluster" -} +variable "allowlist" { + description = "Allowlist configuration details useful for creation" -variable "expires_at" { - description = "timestamp when the allowlist expires" + type = object({ + cidr = string + comment = optional(string) + expires_at = optional(string) + }) } diff --git a/examples/apikey/create_apikey.tf b/examples/apikey/create_apikey.tf index 22e3afcc..7450b9f8 100644 --- a/examples/apikey/create_apikey.tf +++ b/examples/apikey/create_apikey.tf @@ -10,14 +10,10 @@ output "apikey_id" { resource "capella_apikey" "new_apikey" { organization_id = var.organization_id name = var.apikey.name + description = var.apikey.description + expiry = var.apikey.expiry organization_roles = var.apikey.organization_roles allowed_cidrs = var.apikey.allowed_cidrs - resources = [ - { - id = var.project_id - roles = var.resource.roles - type = var.resource.type - } - ] + resources = var.resources } diff --git a/examples/apikey/terraform.template.tfvars b/examples/apikey/terraform.template.tfvars index b00b456c..7eea755e 100644 --- a/examples/apikey/terraform.template.tfvars +++ b/examples/apikey/terraform.template.tfvars @@ -10,8 +10,8 @@ apikey = { expiry = 179 } -resource = { +resources = [{ id = "" roles = ["projectManager", "projectDataReader"] type = "project" -} +}] \ No newline at end of file diff --git a/examples/apikey/variables.tf b/examples/apikey/variables.tf index 802678b4..9d078f9b 100644 --- a/examples/apikey/variables.tf +++ b/examples/apikey/variables.tf @@ -7,10 +7,6 @@ variable "organization_id" { description = "Capella Organization ID" } -variable "project_id" { - description = "Capella Project ID" -} - variable "auth_token" { description = "Authentication API Key" sensitive = true @@ -21,19 +17,20 @@ variable "apikey" { type = object({ name = string - description = string - allowed_cidrs = list(string) + description = optional(string) + allowed_cidrs = optional(list(string)) organization_roles = list(string) - expiry = number + expiry = optional(number) }) } -variable "resource" { +variable "resources" { description = "Resource details useful for apikey creation" - type = object({ + type = list(object({ id = string roles = list(string) - type = string - }) + type = optional(string) + })) + default = [] } \ No newline at end of file diff --git a/internal/resources/apikey.go b/internal/resources/apikey.go index 513a7102..06a36e0a 100644 --- a/internal/resources/apikey.go +++ b/internal/resources/apikey.go @@ -95,7 +95,7 @@ func (a *ApiKey) Create(ctx context.Context, req resource.CreateRequest, resp *r } if !plan.Expiry.IsNull() && !plan.Expiry.IsUnknown() { - expiry := float32(plan.Expiry.ValueFloat64()) + expiry := float32(*plan.Expiry.ValueFloat64Pointer()) apiKeyRequest.Expiry = &expiry } diff --git a/internal/resources/apikey_schema.go b/internal/resources/apikey_schema.go index e8e5dcde..c72bbc05 100644 --- a/internal/resources/apikey_schema.go +++ b/internal/resources/apikey_schema.go @@ -40,7 +40,7 @@ func ApiKeySchema() schema.Schema { }, "organization_roles": stringListAttribute(required, requiresReplace), "resources": schema.ListNestedAttribute{ - Required: true, + Optional: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "id": stringAttribute(required),