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

Possible bug? Using snippets in tfvars causes unmarshal error. #865

Closed
2 tasks done
anthr76 opened this issue Nov 1, 2020 · 6 comments
Closed
2 tasks done

Possible bug? Using snippets in tfvars causes unmarshal error. #865

anthr76 opened this issue Nov 1, 2020 · 6 comments

Comments

@anthr76
Copy link
Contributor

anthr76 commented Nov 1, 2020

Description

Attempting to pass a snippet to a heterogeneous node in a map(list(string)) causes an unmarshall error.

Steps to Reproduce

Provide clear steps to reproduce the bug.

  • Relevant error messages if appropriate (concise, not a dump of everything).
  • Explored using a vanilla cluster from the tutorials. Ruled out customizations.

Expected behavior

terraform plan -var.tfvars & terraform apply -var.tfvars to succeed when referencing snippets in a tfvars file.

Environment

  • Platform: bare-metal
  • OS: flatcar-linux 2605.7.0
  • Release: v1.19.3
  • Terraform: v0.13.5
  • Plugins:
+ provider registry.terraform.io/hashicorp/null v2.1.2
+ provider registry.terraform.io/hashicorp/random v2.3.1
+ provider registry.terraform.io/hashicorp/template v2.1.2
+ provider registry.terraform.io/hashicorp/tls v2.2.0
+ provider registry.terraform.io/poseidon/ct v0.6.1
+ provider registry.terraform.io/poseidon/matchbox v0.4.1

Example usage of snippets in a tfvars:

...
snippets = {
  "node4" = [".cl/longhorn-virt.yaml"],
}
...

Example "snippet" aka CLC

storage:
  filesystems:
    - name: longhorn
      mount: 
        device: /dev/vdb
        format: btrfs
        wipe_filesystem: true
systemd:
  units:
    - name: longhorn.mount
      enabled: true
      contents: |
        [Unit]
        Before=local-fs.target
        [Mount]
        What=/dev/vdb
        Where=/var/lib/longhorn
        Type=btrfs
        [Install]
        WantedBy=local-fs.target

If I'm understanding the documentation for customization and checking the variable definition for varibles.tf this should work?

Instead receiving:

Error: error strict parsing Container Linux Config: error: yaml: unmarshal errors:
  line 1: cannot unmarshal !!str `.cl/lon...` into types.Config

  on profiles.tf line 119, in data "ct_config" "worker-ignitions":
 119: data "ct_config" "worker-ignitions" {
@dghubble
Copy link
Member

dghubble commented Nov 2, 2020

In Terraform, file contents are reference via file('some-file.yaml'). You're setting the map value to the literal ".cl/longhorn-virt.yaml" string. Which naturally won't pass the config validation. The customizations docs show the right usage.

@anthr76
Copy link
Contributor Author

anthr76 commented Nov 2, 2020

Thanks for the prompt reply! The docs seem to show making a modification to the mercury module. Thus requiring a fork and adding my source line as previously mentioned in the docs. If this is the correct way about going about this I will though by the

Extend the snippets map variable

in the docs. I would assume I would be inserting my added snippets in with my tfvars.

After passing file module as a string I get

Error: Invalid attribute name

  on kvmtest.tfvars line 21:
  21:   "node4" = ["file("./cl/longhorn-virt.yaml")"],

An attribute name is required after a dot.

@dghubble
Copy link
Member

dghubble commented Nov 2, 2020

Your new problem is another Terraform syntax error, file should not be quoted. https://www.terraform.io/docs/configuration/functions/file.html

Snippets let you provide CLC or FCC snippets for customization, they do not require a fork.

@anthr76
Copy link
Contributor Author

anthr76 commented Nov 2, 2020

Right.

Fully get what snippets are for. Though the docs are a bit confusing on usage of them.

As noted here https://typhoon.psdn.io/advanced/customization/#flatcar-linux we're pathing the configs within the mercury module

Which if I'm understanding correctly would require a

source = "git::https://github.com/USERNAME/typhoon//digital-ocean/container-linux/kubernetes?ref=myspecialcase"

I totally agree this can be a syntax error, but I'm confused on the usage as per varibles.tf snippets are a map(list(string)) so it made sense to me to pass the file module as a string.

Either way removing the quotes terraform says "functions can't be called here".

@anthr76
Copy link
Contributor Author

anthr76 commented Nov 2, 2020

I'll chalk this up as it's not possible to pass a snippet path within a tfvars file. Thanks for your help, I'll close this out.

@anthr76 anthr76 closed this as completed Nov 2, 2020
@dghubble
Copy link
Member

dghubble commented Nov 2, 2020

I see, you're specifically wanting to set this in the special Terraform tfvars file. I believe tfvarsf files are limited to very simple cases and I don't think you'd be able to use Terraform functions or other Terraform features. But you can refer to Terraform upstream, since this isn't specific to snippets or this project.

The docs only describe writing Terraform declarations in .tf files in a Terraform workspace, so its assumed you can use Terraform syntax and features like file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants