Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a file in terraform module source

Tags:

terraform

Is it possible to exclude a .tf file when specifying the source in a module.

Example

foo/bar consists of multiple .tf files:

  • file1.tf
  • file2.tf
  • file3.tf

Is it possible to exclude file1.tf while including it foo/bar in source as below:

module "module1" {
  source = "foo/bar"
  version = "0.1.0"
}
like image 259
slal Avatar asked Oct 24 '25 22:10

slal


1 Answers

What you're asking for isn't supported explicitly. You can use some of the workarounds detailed in this Medium post, like setting the count of a resource equal to a variable that you've set to boolean true or false:

file1.tf:

resource "aws_eip" "example" {
  count = "${var.create_eip}"
  ...
}

dependent source:

module "module1" {
  source = "foo/bar"
  version = "0.1.0"
  create_eip = false  # set to 'true' to include the resource in file1.tf
}
like image 189
Adil B Avatar answered Oct 28 '25 04:10

Adil B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!