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

[BUG] terramate generate doesn't honor the --tags option #1844

Open
n-my opened this issue Aug 21, 2024 · 2 comments
Open

[BUG] terramate generate doesn't honor the --tags option #1844

n-my opened this issue Aug 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@n-my
Copy link

n-my commented Aug 21, 2024

Describe the bug

To Reproduce

Create 2 stacks, only one with a tag

terramate create stacks/vpc --tags aws
terramate create stacks/vpc2

Add the code generate file stacks/main.tm.hcl with the content

generate_hcl "_generate_main.tf" {
  content {
    resource "aws_vpc" "main" {
      cidr_block = "10.0.0.0/16"
    }
  }
}

Run the generate command only on the 1st stack using the --tags option

terramate generate --tags aws

Expected behavior

I would expect the code generation to be applied only to the 1st stack and not to all. The help page of the terramate generate commands indicates that it supports the --tags=TAGS option to filter stacks by tags.

Log Output

The code generation runs for all stacks

Code generation report
Successes:
- /stacks/vpc
	[+] _generate_main.tf
- /stacks/vpc2
	[+] _generate_main.tf

Environment (please complete the following information):

  • OS: Amazon Linux 2
  • Git Version: 2.40.1
  • Terramate Version: 0.10.1
@n-my n-my added the bug Something isn't working label Aug 21, 2024
@bart-braidwell
Copy link

It works opposite way,
you need to make condition in your template to generate only on stacks with tag aws

generate_hcl "_generate_main.tf" {
  condition = tm_contains(terramate.stack.tags, "aws")

  content {
    resource "aws_vpc" "main" {
      cidr_block = "10.0.0.0/16"
    }
  }
}

then your terramate generate will work

@soerenmartius
Copy link
Contributor

soerenmartius commented Sep 19, 2024

It works opposite way, you need to make condition in your template to generate only on stacks with tag aws

generate_hcl "_generate_main.tf" {
  condition = tm_contains(terramate.stack.tags, "aws")

  content {
    resource "aws_vpc" "main" {
      cidr_block = "10.0.0.0/16"
    }
  }
}

then your terramate generate will work

Thanks for answering this @bart-braidwell, I actually only saw this now. In addition to condition you can also use stack_filter such as repository_paths and project_paths.

This is pretty well documented in https://terramate.io/docs/cli/code-generation/generate-hcl

In addition to that, the code generation always run on the entire repository / Terramate project to prevent inconsistencies as there are plenty of factors that impact generated files such as globals, locals, etc. Partial code generation is not a good idea.

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

No branches or pull requests

3 participants