Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schemahelper: Allow list(any) to be passed into dynamic block's for_each #313

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Sep 5, 2023

When for_each was initially introduced as a "schema extension" we thought it has the same constraints as the "top level" for_each in that it doesn't allow lists. However, since dynamic does not have count inside, the for_each there does allow iterating over lists.

So the updated schema reflects the reality more accurately.

This impacts all functionality driven by schema, i.e.

  • completion
  • hover
  • go-to-definition
  • go-to-references
  • semantic highlighting
  • validation

Example

terraform {
  required_providers {
    cloudinit = {
      source  = "hashicorp/cloudinit"
      version = "~> 2.3"
    }
  }
}

variable "parts" {
  type = list(object({
    filename     = string
    content_type = string
    content      = string
  }))
  default = [
    {
      filename     = "hello-script.sh"
      content_type = "text/x-shellscript"
      content      = "echo 'foo'"
    },
    {
      filename     = "cloud-config.yaml"
      content_type = "text/cloud-config"
      content      = "moot = 42"
    }
  ]
}

data "cloudinit_config" "foobar" {
  gzip          = false
  base64_encode = false

  dynamic "part" {
    for_each = var.parts
    content {
      filename     = part.value.filename
      content_type = part.value.content_type
      content      = part.value.content
    }
  }
}

UX Before

Screenshot 2023-09-05 at 13 26 10

UX After

Screenshot 2023-09-05 at 13 25 37

@radeksimko radeksimko force-pushed the f-allow-lists-in-for_each branch from bafbde4 to f10e9cb Compare September 5, 2023 11:57
@radeksimko radeksimko changed the title schemahelper: Allow list(any) to be passed into for_each schemahelper: Allow list(any) to be passed into dynamic block's for_each Sep 5, 2023
@radeksimko radeksimko force-pushed the f-allow-lists-in-for_each branch from f10e9cb to 32d32ea Compare September 5, 2023 12:20
@radeksimko radeksimko added the bug Something isn't working label Sep 5, 2023
@radeksimko radeksimko marked this pull request as ready for review September 5, 2023 12:27
@radeksimko radeksimko requested a review from a team as a code owner September 5, 2023 12:27
@radeksimko radeksimko merged commit 49d1594 into main Sep 5, 2023
4 checks passed
@radeksimko radeksimko deleted the f-allow-lists-in-for_each branch September 5, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants