I source a git module as below in my Terraform 0.12 code
module "autospotting" {
source = "github.com/autospotting/terraform-aws-autospotting?ref=0.1.1"
...
...
}
At the time of terraform initialization, the below directory structure gets created. Is there a way to move this into a another directory and specify that with terraform init
?
Hi @vikas027,
The .terraform
directory is where Terraform caches some items that need to be retrieved during terraform init
so that they can be used in other Terraform commands. Any module or provider that is being installed from a remote system rather than from the local filesystem will always have its local copy cached under .terraform
, and there is no mechanism to change that. The .terraform
directory is not intended to be included in your version control, so itβs common to put .terraform/*
in your .gitignore
, if youβre using Git.
If your goal is to have a local copy of the module in your own repository so that you are not dependent on an external repository, the best way to do that is to clone the repository for the module in question directly with git clone
and then copy the code from there to the location where you want to keep it in your own repository. Then you can specify that chosen directory using a relative path, rather than a git source:
module "autospotting" {
source = "./modules/autospotting"
}
The standard module structure calls for putting nested modules (those that donβt live in their own separate repositories) in directories under a directory called modules
, which is the convention I followed in the above example. However, you can choose whatever directory structure works for you, as long as the path you give starts with either ./
or ../
to tell Terraform to treat it as a local directory path rather than as a remote source.
2 Likes
Thank you, @apparentlymart. That helps.
@apparentlymart what if the same is being done for git source , so in my case I have something like this structure.
|vault
βββ access_policy
β βββ README.md
β βββ access_policies.tf
β βββ variables.tf
βββ locals.tf
βββ main.tf
βββ outputs.tf
βββ provider.tf
Now I have vault which I am versioning in git tag and I can access via
source = "git::https:// xxxxxxx?ref=1.0.0"
How do I refer this nested module access_policy with git tag source.
Never Mind I was able to solve this using Double slash //
per documentation .