0

I am new to test kitchen and i am trying to use the existing vpc modules i have created earlier using terraform. I am having problems on loading the modules to test kitchen.

My folder structure looks like

tf_aws_cluster
├── .kitchen.yml
├── Gemfile
├── Gemfile.lock
├── README.md
│  ├── modules
|    |── vpc
│       ├── main.tf
│       └── variables.tf
├── main.tf
|── variables.tf

the ~/tf_aws_cluster/.kitchen.yml file

---
driver:
  name: terraform

provisioner:
  name: terraform
  directory: ~/tf_aws_cluster/modules/vpc
  variable_files:
    - variables.tf

my ~/tf_aws_cluster/main.tf file looks like

module "vpc" {
  source         = "../modules/vpc"
  env            = "prod"
  aws_account_id = "************"
}

when i try to run

bundle exec kitchen verify

i am getting an error in loading modules.

-----> Creating <default-ubuntu>...
       Copying configuration from "/home/ubuntu/tf_aws_cluster"...
       Upgrading modules...
       Error downloading modules: Error loading modules: module vpc: failed to get download URL for "../module/vpc": 200 OK resp:<!DOCTYPE html>

what is the values i should pass under provisioner for the module ?

I have tried by giving the full path for the source parameter ~/tf_aws_cluster/main.tf

source         = "~/tf_aws_cluster/modules/vpc/"

this gives me an error as

Error downloading modules: Error loading modules: module vpc: invalid source string: ~/tf_aws_cluster/modules/vpc/
user6826691
  • 1,813
  • 9
  • 37
  • 74

1 Answers1

1

The directory should be a relative path in your directory attribute. Like this:

directory: modules/vpc

Also in the newly released kitchen-terraform v3.0.0 you should be using root_module_directory instead of directory


On a related topic, I would recommend going through the getting started guide to help understand how to do test fixtures as that is what I think you are trying to accomplish with main.tf and modules directory.

I would organize the code as such:

tf_aws_cluster
├── .kitchen.yml
├── Gemfile
├── Gemfile.lock
├── README.md
│  ├── test
|    |── fixtures
|       |── my_module
│          ├── main.tf
│          └── variables.tf
├── main.tf
|── variables.tf

.kitchen.yml

---
driver:
  name: terraform
  directory: test/fixtures/my_module
  variable_files:
    - variables.tf

provisioner:
  name: terraform

the root main.tf:

# this should have your actual Terraform code
resource ... {
  ...
}

the test fixture main.tf (test/fixtures/my_module/main.tf)

# this should have a module reference to your root's main.tf such as:
module "vpc" {
  source         = "source = "../../.."
  env            = "prod"
  aws_account_id = "************"
}
nictrix
  • 1,483
  • 1
  • 17
  • 34