terraform-provider-azureterraform-modules

Module directory does not exist or cannot be read in Terraform


I am trying to use Modules for dependencies in my Terraform code. But even after mentioning that particular source path in module, it gives an error “ Module directory does not exist or cannot be read." and “Unable to evaluate directory – The system cannot find the file specified." Can anyone let me know what can be the reason.

I have to manage 3 different environments with 3 different backend state files for each environment. Here each main file calls the respective module file.The main folder consists of backend config, creation of resource group and it calls modules file

      root
        |
        |-- main 
        |    |--prod  
        |    |--dev    
        |    |--staging
        |-- modules
        |    |--prod   
        |    |--dev     
        |    |--staging

------------CODE-----------------

    provider "azurerm" {
    version = "=2.2.0"
   features {}
    }

    #--- CREATING RESOURCE GROUP PER ENVIRONEMENT
    terraform {
      backend "azurerm" {
        resource_group_name  = ""
        storage_account_name = ""
        container_name       = ""
        key                  = ""
        }
      }


    variable "location" {
      description           =   "Location for deployment of the Azure 
    resources"
   }

     variable "Code" {
       description           =   "Enter a unique two-letter ID to identify 
    customer resources; should match the DynamoDB table."
    }

     variable "EnvironmentType" {
       description       = "Enter a valid environment type. Valid values are 
     Prod, Dev, Staging"
      }

    variable "AccountType" {
      description   = "Select the type of account you wish to create. This 
       will determine which environments and other resources are created."
       }


     resource "azurerm_resource_group" "main" {
      name        = "${var.Code}-${var.EnvironmentType}"
      location    = "${var.location}"
     }

     module "ResourcesStack" {
        source                      = "./modules"
        AccountType                 = "${var.AccountType}"
        CustomerCode                = "${var.Code}"
        EnvironmentType             = "${var.EnvironmentType}"
        location                    = "${var.location}"
      }

Solution

  • Well, with the communication and then I think you did the mistake when you quote the modules in the Terraform code.

    The mistake is that when you want to quote the modules, you need to quote the special one. For example, you want to quote the module dev, then you can quote it in the Terraform code like this:

    module "dev" {
      source      = "./modules/dev"
      ...
    }
    

    Do not set the module source with the root path of all the modules like you did.