{"id":15240474,"url":"https://github.com/infrablocks/rspec-terraform","last_synced_at":"2025-04-10T13:43:04.052Z","repository":{"id":41491635,"uuid":"509872207","full_name":"infrablocks/rspec-terraform","owner":"infrablocks","description":"RSpec support for testing Terraform configurations.","archived":false,"fork":false,"pushed_at":"2025-03-13T11:41:43.000Z","size":382,"stargazers_count":6,"open_issues_count":7,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-24T12:21:47.282Z","etag":null,"topics":["automation","infrastructure","rspec","ruby","ruby-gem","ruby-rspec","rubygem","terraform"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infrablocks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-02T22:17:08.000Z","updated_at":"2025-02-12T10:04:22.000Z","dependencies_parsed_at":"2023-02-10T23:00:55.770Z","dependency_job_id":"a670b651-42ef-432b-9ccf-e1d5ce9e9a1a","html_url":"https://github.com/infrablocks/rspec-terraform","commit_stats":{"total_commits":198,"total_committers":4,"mean_commits":49.5,"dds":0.5656565656565656,"last_synced_commit":"ae209b7b8b3eaa9e7252ea0a111cac6e00034860"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Frspec-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Frspec-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Frspec-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infrablocks%2Frspec-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infrablocks","download_url":"https://codeload.github.com/infrablocks/rspec-terraform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248226292,"owners_count":21068179,"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":["automation","infrastructure","rspec","ruby","ruby-gem","ruby-rspec","rubygem","terraform"],"created_at":"2024-09-29T11:05:09.541Z","updated_at":"2025-04-10T13:43:04.030Z","avatar_url":"https://github.com/infrablocks.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSpec::Terraform\n\nAn RSpec extension for verifying Terraform configurations, with support for:\n\n* unit testing;\n* integration testing;\n* end-to-end testing; and\n* change auditing.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rspec-terraform'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rspec-terraform\n\n## Usage\n\nTo use RSpec::Terraform, require it in your `spec_helper.rb` file:\n\n```ruby\nrequire 'rspec/terraform'\n```\n\nWhen required, RSpec::Terraform automatically configures itself against \nRSpec by:\n\n* adding helper methods to interact with Terraform;\n* adding matchers to verify Terraform plans; and\n* adding settings to control RSpec::Terraform's behaviour.\n\nThe sections below provide further details on each of these additions.\n\n### Helper methods\n\nRSpec::Terraform adds helper methods to the RSpec DSL for planning, applying,\nand destroying Terraform configurations, as well as accessing variables to and\noutputs from Terraform configurations.\n\nEach helper method takes a hash of parameters used to identify the configuration\nagainst which to act and to provide as options to the Terraform command being\nexecuted. Additionally, RSpec::Terraform includes a flexible approach to\nresolving these parameters allowing them to be sourced from a variety of\nlocations. See the [Configuration Providers](#configuration-providers) section\nfor more details.\n\nWhen executing helper methods, RSpec::Terraform provides two execution modes,\n`:in_place` and `:isolated`. By default, RSpec::Terraform works against a\nTerraform configuration _in place_, i.e., it executes commands against the\nTerraform configuration directly, in the location specified. RSpec::Terraform\ncan also operate in an _isolated_ manner, wherein it initialises the\nconfiguration into an isolated directory before executing commands. See the\n[Execution Mode](#execution-mode) section for more details.\n\n#### `plan`\n\nThe `plan` helper produces a Terraform plan for a configuration, reads it\ninto a Ruby representation and returns it.\n\n`plan` requires a `:configuration_directory` parameter, representing the path\nto the configuration to plan and is typically invoked in a `before(:context)`\nhook, with the resulting plan stored for use in expectations:\n\n```ruby\nbefore(:context) do\n  @plan = plan(\n    configuration_directory: 'path/to/configuration/directory'\n  )\nend\n```\n\nIf the configuration has input variables, a `:vars` parameter can be provided\nas a hash:\n\n```ruby\nbefore(:context) do\n  @plan = plan(\n    configuration_directory: 'path/to/configuration/directory',\n    vars: {\n      region: 'uk',\n      zones: ['uk-a', 'uk-b'],\n      tags: {\n        name: 'important-thing',\n        role: 'persistence'\n      }\n    }\n  )\nend\n```\n\nor within a block:\n\n```ruby\nbefore(:context) do\n  @plan = plan(\n    configuration_directory: 'path/to/configuration/directory'\n  ) do |vars|\n    vars.region = 'uk'\n    vars.zones = ['uk-a', 'uk-b']\n    vars.tags = {\n      name: 'important-thing',\n      role: 'persistence'\n    }\n  end\nend\n```\n\n`plan` accepts an optional `:state_file` parameter with the path to where the\ncurrent state file for the configuration is located, useful when checking the\nincremental change that applying the configuration would have after a previous\napply.\n\nInternally, `plan`:\n* calls `terraform init` to initialise the configuration directory;\n* calls `terraform plan` to produce a plan file;\n* calls `terraform show` to read the contents of the plan file into a Ruby\n  representation; and\n* deletes the plan file.\n\nAny additional parameters passed to `plan` are passed on to the underlying\nTerraform invocations.\n\n#### `apply`\n\n#### `destroy`\n\n#### `output`\n\n#### `var`\n\n### Plan Matchers\n\n### Settings\n\n#### Binary Location\n\n#### Logging and Standard Streams\n\n#### Execution Mode\n\nThe benefit of isolated execution is that nothing is carried over between test\nruns and providers and modules are fetched into a clean configuration directory\nevery time. The downside is additional test run time.\n\n#### Configuration Providers\n\n### Frequently Asked Questions\n\n## Development\n\nTo install dependencies and run the build, run the pre-commit build:\n\n```shell\n./go\n```\n\nThis runs all unit tests and other checks including coverage and code linting /\nformatting.\n\nTo run only the unit tests, including coverage:\n\n```shell\n./go test:unit\n```\n\nTo attempt to fix any code linting / formatting issues:\n\n```shell\n./go library:fix\n```\n\nTo check for code linting / formatting issues without fixing:\n\n```shell\n./go library:check\n```\n\nYou can also run `bin/console` for an interactive prompt that will allow you to\nexperiment.\n\n### Managing CircleCI keys\n\nTo encrypt a GPG key for use by CircleCI:\n\n```bash\nopenssl aes-256-cbc \\\n  -e \\\n  -md sha1 \\\n  -in ./config/secrets/ci/gpg.private \\\n  -out ./.circleci/gpg.private.enc \\\n  -k \"\u003cpassphrase\u003e\"\n```\n\nTo check decryption is working correctly:\n\n```bash\nopenssl aes-256-cbc \\\n  -d \\\n  -md sha1 \\\n  -in ./.circleci/gpg.private.enc \\\n  -k \"\u003cpassphrase\u003e\"\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at \nhttps://github.com/infrablocks/rspec-terraform. This project is intended to be a \nsafe, welcoming space for collaboration, and contributors are expected to \nadhere to the [Contributor Covenant](http://contributor-covenant.org) code of \nconduct.\n\n## License\n\nThe gem is available as open source under the terms of the \n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfrablocks%2Frspec-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfrablocks%2Frspec-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfrablocks%2Frspec-terraform/lists"}