ned1313 / terraform-cloudinit-native

A Terraform module to generate cloud init file natively without a provider plugin or data source.
MIT License
1 stars 1 forks source link

Support var values other than strings #1

Open nk9 opened 2 years ago

nk9 commented 2 years ago

One of the main benefits of the new templatefile function over the old template_file is that the new one lets you pass any object you want as a var value. However, when I try to use this module with a map, it fails saying that:

The given value is not suitable for child module variable "cloudinit_parts"
│ defined at
│ .terraform/modules/project_module.cloud_init_config/variables.tf:2,1-27:
│ element 0: attribute "vars": element "SSH_KEYS": string required.

Here's the code I'm using:

module "cloud_init_config" {
  source = "ned1313/native/cloudinit"

  cloudinit_parts = [
    {
      filepath = "${path.module}/templates/bastion_cloud-init.yml.tpl"
      content-type = "text/cloud-config"
      vars = {
        SSH_KEYS = { for user in local.users: user => module.user_key_pairs[user].public_key_openssh }
      }
    }
  ]
}
ned1313 commented 2 years ago

Thanks Nick! I'll take a look.

On Sun, Jul 24, 2022, 8:48 PM Nick Kocharhook @.***> wrote:

One of the main benefits of the new templatefile function over the old template_file is that the new one lets you pass any object you want as a var value. However, when I try to use this module with a map, it fails saying that:

The given value is not suitable for child module variable "cloudinit_parts"

│ defined at

│ .terraform/modules/project_module.cloud_init_config/variables.tf:2,1-27:

│ element 0: attribute "vars": element "SSH_KEYS": string required.

Here's the code I'm using:

module "cloud_init_config" {

source = "ned1313/native/cloudinit"

cloudinit_parts = [

{

  filepath = "${path.module}/templates/bastion_cloud-init.yml.tpl"

  content-type = "text/cloud-config"

  vars = {

    SSH_KEYS = { for user in local.users: user => module.user_key_pairs[user].public_key_openssh }

  }

}

]

}

— Reply to this email directly, view it on GitHub https://github.com/ned1313/terraform-cloudinit-native/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTIYZJGAHIMPHFQ3ZRTYKDVVXP6LANCNFSM54QQN4IQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>