A demo on how Terraform works with AWS and can be tested w/Kitchen
- Setup VSCode
- Download VSCode from the official Microsoft site, select the linux Debian package if you're using Ubuntu: https://code.visualstudio.com/docs/?dv=linux64_deb
- Run the package install
- Install the Terraform VSCode plugin
- Setup Terraform
- Download the terraform zipped file from https://learn.hashicorp.com/terraform/getting-started/install.html
- Unzip the package and place it under
/usr/local/bin
- Install RVM following the guide: https://rvm.io/rvm/install
- Make sure you also install ruby 2.6.0 using RVM.
- Declare kitchen-terraform as a gem in a Gemfile
- Run
bundle install
to download the necessary dependencies.
- Run
- Setup AWS credentials.
- Install aws cli: https://docs.aws.amazon.com/es_es/cli/latest/userguide/install-linux-al2017.html
- Create an AWS IAM user and attach
AmazonS3FullAccess
policy to it. Don't forget to give programmatic access to the user. - Run
aws configure
and setup your credentials based off from thecredentials.csv
file.
- Create a
main.tf
,outputs.tf
andvariables.tf
files and add theaws
provider tomain.tf
. - Declare the desired S3 bucket resource
- Declare the s3 bucket object resources. (the files). Don't forget to set the timestamp as the content.
- Create kitchen test case
- Create folder
test/fixtures/tf_module
for storing our terraform plan managed by kitchen - Create
main.tf
,outputs.tf
andvariables.tf
files intest/fixtures/tf_module
to call the real terraform plan as a module - Create a folder that will hold our tests:
test/integration/default/controls
- Create the
kitchen.yml
andtest/integration/default/inspec.yml
files and reference the created directories inkitchen.yml
as per kitchen config. - Create the
testing.tfvars
file for the test variables to be used for the module. - Add the tests under
test/integration/default/
- Run
bundle exec kitchen converge
to apply the state - Run
bundle exec kitchen verify
to verify the state as per tests - Run
bundle exec kitchen destroy
to destroy the resources created by kitchen
- Create folder