[Learn Lab] Test your Terraform configuration

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • Terraform 1.6 lets you write unit and integration tests for your configuration and run them before deploying infrastructure, with the new “terraform test” command.
    In this Learn Lab, you will write tests using the new test file syntax. Then you will develop your own testing strategy using the many ways Terraform supports deployment validation: check blocks, preconditions, postconditions, and now tests.
    Speaker: Brian McClain
    Subscribe to our RUclips Channel → www.youtube.co...
    For hands-on interactive labs, visit HashiCorp Developer → developer.hash...
    HashiCorp provides infrastructure automation software for multi-cloud environments, enabling enterprises to unlock a common cloud operating model to provision, secure, connect, and run any application on any infrastructure. HashiCorp tools Vagrant, Packer, Terraform, Vault, Consul, Nomad, Boundary, and Waypoint allow organizations to deliver applications faster by helping enterprises transition from manual processes and ITIL practices to self-service automation and DevOps practices.
    For more information → hashicorp.com
    Twitter → / hashicorp
    LinkedIn → / hashicorp
    Facebook → / hashicorp

Комментарии • 6

  • @SeeRay
    @SeeRay Месяц назад

    Hi! Can we run tests for modules with tags instead of branches? It is not possible to change anything in the configuration.

    • @HashiCorp
      @HashiCorp  Месяц назад

      Currently, the integrated testing feature is limited to the branch-based module publishing method. Extending this to tag-based modules is something we plan to address in the future based on customer feedback.

  • @lokendrajain1534
    @lokendrajain1534 4 месяца назад

    how can we get code coverage report ( eg. how much test % are passed or fail ?)

    • @HashiCorp
      @HashiCorp  4 месяца назад

      Terraform and Terraform Cloud don’t natively show the % of passed/failed tests, but if you’re using the CLI workflow, adding the -json flag (i.e. terraform test -json) will output the test summary in JSON format that you can parse:
      {"@level":"info","@message":"Success! 2 passed, 0 failed.","@module":"terraform.ui","@timestamp":"2024-04-16T12:01:52.025416-04:00","test_summary":{"status":"pass","passed":2,"failed":0,"errored":0,"skipped":0},"type":"test_summary"}
      From this, you could calculate the percent of tests that passed and failed.

  • @anooppc7
    @anooppc7 3 месяца назад

    How can we utilize Terraform test to assess modifications or additions to an existing infrastructure, such as introducing a new
    VM or modifying existing ones, especially when there are already 50 VMs in the environment? This scenario arises frequently when clients are reluctant to allocate a separate testing environment or disrupt the existing setup.

    • @HashiCorp
      @HashiCorp  3 месяца назад +1

      The Terraform test framework is intended to be used while developing module code, not during normal operations like your scenario. Tests always execute with a temporary in-memory state, they don’t operate on existing states. For your scenario, a combination of an approval workflow around examining plan outputs before applying changes, and something like the Sentinel policy framework available in HCP Terraform would be more relevant than the Terraform test framework.