0
votes

Why do I get the following error?

Using Terraform and following the official published guide here I'm trying to create a simple compartment on OCI and get the following error:

│ Error: Error in function call │ │ on .terraform/modules/iam_compartment/modules/iam-compartment/main.tf line 36, in locals: │ 36: 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.

My terraform main.tf file:

module "iam_compartment" {
  source                  = "oracle-terraform-modules/iam/oci//modules/iam-compartment"
  version = "2.0.1"
  tenancy_ocid            = var.provider.tenancy_id
  compartment_id          = var.provider.tenancy_id
  compartment_name        = "tf_example_compartment"
  compartment_description = "compartment created by terraform"
  compartment_create      = true
  enable_delete           = true
}

Version:

Terraform v1.1.3 on darwin_amd64

  • provider registry.terraform.io/hashicorp/oci v4.59.0
  • provider registry.terraform.io/hashicorp/template v2.2.0

Steps to recreate

  • terraform init
  • terraform plan
1

1 Answers

1
votes

The module you are using is not up to date with the latest Terraform version. Moreover, it contains code which is is not forward compatible.

As the error says, the map function in Terraform was deprecated in favor of tomap function. If we take a look at the source code for the module on GitHub, it is using using map function:

locals {
  compartment_ids        = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(map("id", "")))
  parent_compartment_ids = concat(flatten(data.oci_identity_compartments.this.*.compartments), list(map("compartment_id", "")))
}

Also, there is an issue reported for this problem, without any recent activity.

Since, this module is from a third party, what you can do is to fork it on GitHub and fix change map function to tomap. Potentially, you could create pull request with the fix.

Other option would be to get rid of this module, and build the its functionality yourself.