Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform init not working when specifying modules

I am new to terraform and trying to fix a small issue which I am facing when testing modules.

Below is the folder structure I have in my local computer.

enter image description here

I have below code at storage folder level

#-------storage/main.tf

provider "aws" {
  region = "us-east-1"
}

resource "aws_s3_bucket" "my-first-terraform-bucket" {
    bucket = "first-terraform-bucket"
    acl = "private"
    force_destroy = true
}

And below snippet from main_code level referencing storage module

#-------main_code/main.tf

module "storage" {
    source = "../storage"
}

When I am issuing terraform init / plan / apply from storage folder it works absolutely fine and terraform creates the s3 bucket.

But when I am trying the same from main_code folder I am getting the below error -

main_code@DFW11-8041WL3: terraform init
Initializing modules...
- module.storage
Error downloading modules: Error loading modules: module storage: No Terraform configuration files found in directory: .terraform/modules/0d1a7f4efdea90caaf99886fa2f65e95

I have read many issue boards on stack overflow and other github issue forums but did not help resolving this. Not sure what I am missing!

like image 892
sai kumar Avatar asked Jun 17 '26 16:06

sai kumar


2 Answers

I agree the comments from @rclement.

Several ways to troubleshooting terraform issues.

  1. Clean .terraform folder and rerun terraform init.

This is always the first choice. But it takes time when you run terraform init next time, it starts installing all providers and modules again.

  1. If you don't want to clean .terraform to save the deployment time, you can run terraform get --update=true

Most case is, you did some changes in modules, and it need be refreshed.

like image 88
BMW Avatar answered Jun 21 '26 08:06

BMW


Just update the existing modules by running terraform get --update. If this not work delete the .terraform folder.

like image 33
Vaibhav Jain Avatar answered Jun 21 '26 06:06

Vaibhav Jain



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!