1

I am trying to setup terraform with modules and when doing terraform init after creating a module I have ran into an issue where I am told it does not exist or can't be read. I've checked many times and tried many paths to it and it does exist where I think it does.

Not sure in that case why it can't be read. I've included my main.tf file as well as the modules/queues.tf file

main.tf
  | main.tf
  | modules
     | queues.tf

main.tf

# This file brings together all of the modules
variable "environments" {
  type = list(string)
}


module "pae_queues" {
    source = "./modules/queues.tf"

    environments = "${var.environments}"
}

queues.tf

variable "environments" {
  type = "list(string)"
}

resource "aws_sqs_queue" "email_queue_${var.environments[count.index]}" {
  count = length(${var.environments})
  name                      = "email_queue_${var.environments[count.index]}"
  delay_seconds             = 0
  max_message_size          = 2048
  message_retention_seconds = 86400
  receive_wait_time_seconds = 10
  redrive_policy            = "{\"deadLetterTargetArn\":\"${aws_sqs_queue.terraform_queue_deadletter.arn}\",\"maxReceiveCount\":3}"

  tags = {
    Environment = "${var.environments[count.index]}"
  }
}


2

A Terraform module is represented by a whole directory, not an individual file. If you create a directory ./modules/queues and move ./modules/queues.tf to ./modules/queues/queues.tf then you can call that module like this:

module "pae_queues" {
  source = "./modules/queues"

  environments = var.environments
}
2
  • I had tried moving it to it's own directory (after posting) but was calling still a specific file in that directory but that failed. So I just have to call the directory not any particular file? – joshk132 Nov 5 '19 at 1:04
  • Yes, a Terraform module is a directory of .tf files, not an individual .tf file. – Martin Atkins Nov 5 '19 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.