oracle-terraform-modules/terraform-oci-iam

Locals in iam-compartment causing error with Terraform 1.0.10

ziondef opened this issue · 3 comments

The iam-compartment module's maint.tf line for "locals" is causing an error when using terraform plan. It says "map" is deprecated since 0.12 and to use "tomap". When using "tomap" function with replacing the parentheses with curly braces, it prompts for commas.

Error set #1 with map function:

│ Error: Error in function call
│ 
│   on modules/iam-default-compartment/main.tf line 33, in locals:
│   33:   compartment_ids        = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(map("id", "")))
│ 
│ Call to function "map" failed: the "map" function was deprecated in Terraform v0.12 and is no longer available; use tomap({ ... }) syntax to write a literal map.
╵
╷
│ Error: Error in function call
│ 
│   on modules/iam-default-compartment/main.tf line 34, in locals:
│   34:   parent_compartment_ids = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(map("compartment_id", "")))
│ 
│ Call to function "map" failed: the "map" function was deprecated in Terraform v0.12 and is no longer available; use tomap({ ... }) syntax to write a literal map.

Error #2 with tomap function

╷
│ Error: Missing argument separator
│ 
│   on modules/iam-default-compartment/main.tf line 33, in locals:
│   33:   compartment_ids        = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(tomap{"id", ""}))
│ 
│ A comma is required to separate each function argument from the next.
╵
╷
│ Error: Missing argument separator
│ 
│   on modules/iam-default-compartment/main.tf line 34, in locals:
│   34:   parent_compartment_ids = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(tomap{"compartment_id", ""}))
│ 
│ A comma is required to separate each function argument from the next.

Updating the locals to the following got me past those errors

locals {
  compartment_ids        = concat(flatten(data.oci_identity_compartments.this.*.compartments), tolist([tomap({id = ""})]))
  parent_compartment_ids = concat(flatten(data.oci_identity_compartments.this.*.compartments), tolist([tomap({compartment_id = ""})]))
}

However now I receive the following:

╷
│ Error: Error in function call
│ 
│   on modules/iam-default-compartment/outputs.tf line 6, in output "compartment_id":
│    6:   value = var.compartment_create ? element(concat(oci_identity_compartment.this.*.id, list("")), 0) : lookup(local.compartment_ids[0], "id")
│ 
│ Call to function "list" failed: the "list" function was deprecated in Terraform v0.12 and is no longer available; use tolist([ ... ]) syntax to write a literal list.
╵
╷
│ Error: Error in function call
│ 
│   on modules/iam-default-compartment/outputs.tf line 12, in output "parent_compartment_id":
│   12:   value = var.compartment_create ? element(concat(oci_identity_compartment.this.*.compartment_id, list("")), 0) : lookup(local.parent_compartment_ids[0], "compartment_id")
│ 
│ Call to function "list" failed: the "list" function was deprecated in Terraform v0.12 and is no longer available; use tolist([ ... ]) syntax to write a literal list.

I had to update lines 3-13 on module's outputs.tf to read:

output "compartment_id" {
  description = "Compartment ocid"
  // This allows the compartment ID to be retrieved from the resource if it exists, and if not to use the data source.
  value = var.compartment_create ? element(concat(oci_identity_compartment.this.*.id, tolist([""])), 0) : lookup(local.compartment_ids[0], "id")
}

output "parent_compartment_id" {
  description = "Parent Compartment ocid"
  // This allows the compartment ID to be retrieved from the resource if it exists, and if not to use the data source.
  value = var.compartment_create ? element(concat(oci_identity_compartment.this.*.compartment_id, tolist([""])), 0) : lookup(local.parent_compartment_ids[0], "compartment_id")
}

SUCCESS!

Thank you for this it saved me some time. I hope this gets added to a PR to fix soon. :)