Using kitchen-terrform to set up extra context

0 votes

I'm using kitchen-terraform in order to verify a terraform module I'm building. The module is a part of a larger infra. It's dependent on some of the network being available. where later it's used to spin more servers etc.

I just want to know if there's a way in kitchen-terraform to create some pieces of infra before the module is tested.

In my case it's creating a new VPC with some connections and with existing PVC, security groups and subnets. I want to verify that the peering connections were established correctly as well as spin up some ec2 instances to verify the status of the network.

Aug 7, 2018 in DevOps & Agile by ffdfd
• 5,550 points
697 views

1 answer to this question.

0 votes

Use .kitchen.yml file which cans specify where the terraform code exists to execute:

provisioner:
  name: terraform
  directory: path/to/terraform/code
  variable_files:
   - path/to/terraform/variables.tfvars

Create a main.tf in the test location which will buld all the infrastucture you want. the order of execution should be controlled by the dependencies of the resources.

Taking that your testing is in the same repository as your module, do something like this:

├── .kitchen.yml
├── Gemfile
├── Gemfile.lock
├── README.md
├── terraform
│   ├── my_module
│       ├── main.tf
│       └── variables.tf
├── test
    ├── main.tf
    └── terraform.tfvars


the .kitchen.yml file should look something like this:

provisioner:
  name: terraform
  directory: test
  variable_files:
   - test/variables.tfvars
  variables:
    access_key: <%= ENV['AWS_ACCESS_KEY_ID'] %>
    secret_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>

Your test/main.tf will create the module with any other test code you want:

provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region = "${var.region}"
}

...

module "my_module" {
  name = "foo"
  source = "../terraform/my_module"
...
}

resource "aws_instance" "test_instance_1" {
...
}
answered Aug 7, 2018 by ajs3033
• 7,300 points

Related Questions In DevOps & Agile

0 votes
1 answer

unable to build .Net project using NUGet

you just need the developer pack for ...READ MORE

answered Apr 3, 2018 in DevOps & Agile by ajs3033
• 7,300 points
946 views
+13 votes
2 answers
0 votes
1 answer

Is it possible to to create IIS Site and application Pool using Web Deploy

You can try and use the ServerManager ...READ MORE

answered Apr 20, 2018 in DevOps & Agile by ajs3033
• 7,300 points
2,067 views
0 votes
1 answer

Using Postman Client to send web request to TFS

Try using Basic Auth. Fill the PAT ...READ MORE

answered Apr 24, 2018 in DevOps & Agile by DareDev
• 6,890 points
2,288 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,066 views
+2 votes
1 answer
0 votes
1 answer

How to set up a VM with KVM/qemu without VitualBox using Vagrant

Start the vagrant box using: vagrant up --provider=kvm But ...READ MORE

answered Apr 11, 2018 in DevOps & Agile by ajs3033
• 7,300 points
2,435 views
+2 votes
2 answers

how to set different provisioning profiles for different targets using Xcode Build

For multiple targets, each task has to ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by ajs3033
• 7,300 points

edited Oct 16, 2018 by Kalgi 4,854 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP