'Running terraform init in a directory that only contains a tfvars file that references a git source
I am trying to use terraform in a way that was described at the end of the Terraform Up and Running book. The pattern described says that you can have a repo that defines your live environments by using *.tfvars files for each environment (such as prod, dev, ad-hoc developer environments, etc.) These *.tfvars files reference modules in another repo like this:
source = "git::https://github.com/github-user/my-module.git?ref=v0.0.1"
# required variables for `my-module` defined here
foo="bar"
This pattern makes a lot of sense to me, it is DRY an d also makes it easy to compare configuration differences between environments.
When I try to run terraform init in a directory that contains a file called terraform.tfvars with a reference to my remote module, I get errors. Here's my terraform.tfvars file:
source = "git::https://github.com/briancaffey/terraform-aws-django.git?ref=v0.0.2"
region="us-east-1"
...
Here's the error that I get when I run terraform init or terraform init -var-file terraform.tfvars or if I specify -backend-config values for my s3 backend:
Terraform initialized in an empty directory!
The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.
I had a hard time finding examples that show this pattern, and I also couldn't find anything in the terraform documentation that shows how to use source in a *.tfvars file.
Is what I'm trying to do possible? I'm not sure if this complicates things, but the remote terraform module that I am trying to reference is also published to the official terraform registry: https://registry.terraform.io/modules/briancaffey/django/aws/latest.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
