Skip to content

Commit

Permalink
[AV-68397] API Key & Allowlist creation does not need optional fields (
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhi07kumar authored Nov 30, 2023
1 parent 06e482e commit df445f2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 36 deletions.
6 changes: 3 additions & 3 deletions examples/allowlist/create_allowlist.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions examples/allowlist/terraform.template.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ organization_id = "<organization_id>"
project_id = "<project_id>"
cluster_id = "<cluster_id>"
host = "https://cloudapi.cloud.couchbase.com"
cidr = "10.0.0.0/16"
expires_at = "2023-11-30T23:59:59.465Z"

allowlist = {
cidr = "10.0.0.0/16"
comment = "Allow access from a public IP"
expires_at = "2023-12-30T23:59:59.465Z"
}
16 changes: 7 additions & 9 deletions examples/allowlist/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
10 changes: 3 additions & 7 deletions examples/apikey/create_apikey.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

4 changes: 2 additions & 2 deletions examples/apikey/terraform.template.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ apikey = {
expiry = 179
}

resource = {
resources = [{
id = "<project_id>"
roles = ["projectManager", "projectDataReader"]
type = "project"
}
}]
19 changes: 8 additions & 11 deletions examples/apikey/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
}
2 changes: 1 addition & 1 deletion internal/resources/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/apikey_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit df445f2

Please sign in to comment.