{"id":15156425,"url":"https://github.com/vistaprint/tfmodtest","last_synced_at":"2025-09-30T05:30:23.068Z","repository":{"id":62558864,"uuid":"114899905","full_name":"vistaprint/tfmodtest","owner":"vistaprint","description":"A ruby gem to make testing easy in Terraform modules.","archived":true,"fork":false,"pushed_at":"2020-03-24T21:56:01.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-16T00:21:26.596Z","etag":null,"topics":["gem","ruby","terraform","terraform-module","testing"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vistaprint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-20T15:00:46.000Z","updated_at":"2023-10-31T15:39:38.000Z","dependencies_parsed_at":"2022-11-03T11:00:26.373Z","dependency_job_id":null,"html_url":"https://github.com/vistaprint/tfmodtest","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistaprint%2Ftfmodtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistaprint%2Ftfmodtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistaprint%2Ftfmodtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vistaprint%2Ftfmodtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vistaprint","download_url":"https://codeload.github.com/vistaprint/tfmodtest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234702092,"owners_count":18873828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","ruby","terraform","terraform-module","testing"],"created_at":"2024-09-26T19:21:19.710Z","updated_at":"2025-09-30T05:30:22.394Z","avatar_url":"https://github.com/vistaprint.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform Module Testing\n\n[![Build Status](https://travis-ci.org/vistaprint/tfmodtest.svg?branch=master)](https://travis-ci.org/vistaprint/tfmodtest)\n[![Gem Version](https://badge.fury.io/rb/tfmodtest.svg)](https://badge.fury.io/rb/tfmodtest)\n\nTerraform Module Testing is a set of rake tasks to easily enable testing for Terraform Module developement. It allows developers to specify tests in a rake task to test remote infrastructure is created as expected when using a module. It then destroys the environment after the test has run.\n\nCurrently this repository is tightly coupled with AWS and has not been tested to work with other providers. We are actively working to change this and hope to have a more generic solution soon. If you would like to see support for your favourite cloud provider please have submit a pull request implementing support and we will be more than happy to merge your changes in.\n\n# Installation\nAdd this line to your application's Gemfile:\n\n`gem 'tfmodtest'`  \n\nAnd then execute:\n\n`$ bundle`  \n\nOr install it yourself as:\n\n`$ gem install tfmodtest`\n\n## Getting started\n\n### A Minimal Rakefile\n\nIn the root of your repository add a `Rakefile` with the following contents:\n\n```ruby\nrequire 'tfmodtest/module_tasks'\n```\n\n# Adding tests \n\nIn your repository create `test/\u003cmy_module\u003e/Rakefile` and add:\n\n```ruby\nnamespace '\u003cyour_modules_namespace\u003e' do\n  # Required: Import TerraformDevKit base rake tasks.\n  # Set the root path of our tests to our location. \n  # TerraformDevKit uses this path as the base from where\n  # all operations are run.\n  ROOT_PATH = File.dirname(File.expand_path(__FILE__))\n  spec = Gem::Specification.find_by_name 'TerraformDevKit'\n  load \"#{spec.gem_dir}/tasks/devkit.rake\"\n\n  # Optional: Use RSpec to run tests.\n  begin\n    require 'rspec/core/rake_task'\n    RSpec::Core::RakeTask.new(:spec)\n  rescue LoadError\n    raise 'Rspec not found'\n  end\n\n  # Required: Add a hook into TerraformDevKit to \n  # run tests for your module. \n  task :custom_test, [:env] =\u003e :spec\nend\n```\n\nThe `custom_test` task is a hook in TerraformDevKit that is called once all the infrastructure is created. You can see a full list of useful hooks in TerraformDevKit [here](https://github.com/vistaprint/TerraformDevKit#tasks-and-hooks)\n\nCreate `test/\u003cmy_module\u003e/config/config-dev.yml` that contains:\n\n```yml\nterraform-version: 0.12.24\nproject-name: my module tests\naws:\n  profile: \u003cprofile\u003e\n  region: \u003cregion\u003e\n```\n\nThis configuration determines where Terraform will create the infrastructure during test execution. \n\nFinally to create your infrastructure under test place a `main.tf.mustache` file in `test/\u003cmy_module\u003e`. This is the file TerraformDevKit will use to create you infrastructure. \n\n```hcl\nprovider \"aws\" {\n  # Use the profile specified in config/config-dev.yml\n  profile = \"{{Profile}}\"\n  region  = \"us-east-1\"\n}\n\nresource \"aws_s3_bucket\" \"b\" {\n  # Use the Environment name as part of the bucket name\n  bucket = \"{{Environment}}my-tf-test-bucket\"\n  acl    = \"private\"\n\n  tags {\n    Name        = \"My bucket\"\n    Environment = \"Dev\"\n  }\n}\n```\n\n## Optional but recommended\n\n[`awspec`](https://github.com/k1LoW/awspec) is a Ruby gem for running `rspec` tests against AWS infrastructure. It eases the pain of running tests against AWS:\n\n```ruby\ndescribe cloudwatch_alarm(\"www.example.com-5xxErrorRate\") do\n  it { should exist }\n  it { should belong_to_metric('5xxErrorRate').namespace('AWS/CloudFront') }\nend\n```\n\nTo start using `awspec` follow the [Getting Started ](https://github.com/k1LoW/awspec#getting-started) \n\n# Requirements\n\n* Terraform 0.12.0 or above\n\n# Development\n\nTo install this gem locally run `rake install` You should then be able to reference it in your local projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvistaprint%2Ftfmodtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvistaprint%2Ftfmodtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvistaprint%2Ftfmodtest/lists"}