I’m not sure where the main discussion for the terraform test
command lives so I started this topic because I’d like to know what plans there are for its future?
I’ve just started using it in the last month. I’ve made a few modules that use the command exclusively as a test framework.
I would like to be able to write integration and unit test in Terraform as opposed to using a framework based on another language like Go, Python, etc.
My argument for that is because it creates a barrier. I work at a company with over 1000 engineers, we have a large Terraform code base. We exclusively use Terratest. Its difficult to get new developers to dive into learning Terraform and then also right into writing test since they need to learn the Go language, at least enough to understand how to write basic integration test. As a result, the load has been put off to a chosen few to keep writing test for modules we develop.
I believe that if terrafom test
were further developed and pulled out of experimental phase and into full development phase, I could easily make an argument for switching for the following reasons:
- You can write test in the same language as the module you are developing.
- It would be considered supported by HashiCorp long-term and safe to use.
- Existing limitations we could vote for to be fixed based on urgency.
Right now you can do a lot of basic test with the experiment as it stands. This aws-tf-s3-website module I have developed recently sets up a website (using S3 and CloudFront for HTTPS support). The test sets up all the infrastructure, uploads a simple web page, then asserts on the HTTPS response body:
resource "test_assertions" "website_deployed" {
component = "website_deployed"
depends_on = [
module.main,
data.http.test_page_response,
]
# assert a domain validation was made
# asserts that:
# a bucket with the domain name was made
# files cab be uploaded to the bucket
# the policy on the bucket allows access from this CloudFront distribution
# a valid ACM certificate was issue for the domain
# HTTPS is working via the CloudFront distribution
equal "get_response" {
description = "assert response from fixture test page"
want = "hi world!"
got = data.http.test_page_response.response_body
}
}
I’ve said a bit, so let me stop here.