sourcefuse / terraform-aws-arc-ecs

Repo for managing the ECS Fargate Terraform Module.
Apache License 2.0
1 stars 3 forks source link

Add Integration Test using new Terraform framework #63

Open mayank0202 opened 3 months ago

mayank0202 commented 3 months ago

Is your feature request related to a problem? Please describe. Terraform tests let authors validate that module configuration updates do not introduce breaking changes. Tests run against test-specific, short-lived resources, preventing any risk to your existing infrastructure or state.

Describe the solution you'd like The following example demonstrates a simple Terraform configuration that creates an AWS S3 bucket, using an input variable to modify the name. We will create an example test file (below) that validates the buckets name is created as expected.

# main.tf
 
provider "aws" {
    region = "eu-central-1"
}
 
variable "bucket_prefix" {
  type = string
}
 
resource "aws_s3_bucket" "bucket" {
  bucket = "${var.bucket_prefix}-bucket"
}
 
output "bucket_name" {
  value = aws_s3_bucket.bucket.bucket
}

The following test file runs a single Terraform plan command which creates the S3 bucket, and then validates the logic for calculating the name is correct by checking the actual name matches the expected name.

# valid_string_concat.tftest.hcl
 
variables {
  bucket_prefix = "test"
}
 
run "valid_string_concat" {
 
  command = plan
 
  assert {
    condition     = aws_s3_bucket.bucket.bucket == "test-bucket"
    error_message = "S3 bucket name did not match expected"
  }
 
}