Skip to content

Value Conversion Error when using dynamic files in a reference_table #3437

@Cavaler

Description

@Cavaler

Datadog Terraform Provider Version

v3.84.0

Terraform Version

v1.14.3

What resources or data sources are affected?

datadog_reference_table

Terraform Configuration Files

locals {
  tables = {
    common_edge_vessel_name_ref_table = {
      desc = "This is a lookup table to match Common Edge site ID to human readable name e.g. Mardi Gras."
      keys = ["id", "name"]
    }
    common_edge_node_id_ref_table_test = {
      desc = "Table for referencing a node_id to a site_id"
      keys = ["node_id", "site_id"]
    }
  }
}

resource "aws_s3_object" "table_upload" {
  for_each = local.tables

  bucket      = "terraform"
  key         = "reference-tables/${each.key}.csv"
  source      = "${path.module}/resources/${each.key}.csv"
  source_hash = filemd5("${path.module}/resources/${each.key}.csv")
}

resource "datadog_reference_table" "reference_table" {
  for_each    = local.tables
  table_name  = each.key
  description = each.value.desc
  source      = "S3"

  file_metadata {
    sync_enabled = true

    access_details {
      aws_detail {
        aws_account_id  = var.aws_account_id
        aws_bucket_name = aws_s3_object.table_upload[each.key].bucket
        file_path       = aws_s3_object.table_upload[each.key].key
      }
    }
  }

  schema {
    primary_keys = [each.value.keys[0]]

    dynamic "fields" {
      for_each = each.value.keys
      content {
        name = fields.value
        type = "STRING"
      }
    }
  }

  tags = [
    "common-edge"
  ]
}

Relevant debug or panic output

https://gist.github.com/Cavaler/8e59ea46856eb7704eccf7986af840db

Expected Behavior

Should have planned to create the reference table accordingly

Actual Behavior

Fails to create a plan due to an error, "This is always an error in the provider" terraform says.

Steps to Reproduce

terraform plan

Important Factoids

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions