Skip to content

Commit

Permalink
add snippets about terraform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shibataka000 committed Oct 25, 2023
1 parent f3e179f commit f09d129
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions terraform/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "ap-northeast-1"
}
3 changes: 3 additions & 0 deletions terraform/tests/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "bucket_name" {
value = aws_s3_bucket.bucket.bucket
}
3 changes: 3 additions & 0 deletions terraform/tests/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "aws_s3_bucket" "bucket" {
bucket = "${var.bucket_prefix}-bucket"
}
29 changes: 29 additions & 0 deletions terraform/tests/s3.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variables {
bucket_prefix = "test"
}

run "uses_root_level_value" {

command = plan

assert {
condition = aws_s3_bucket.bucket.bucket == "test-bucket"
error_message = "S3 bucket name did not match expected"
}

}

run "overrides_root_level_value" {

command = plan

variables {
bucket_prefix = "other"
}

assert {
condition = aws_s3_bucket.bucket.bucket == "other-bucket"
error_message = "S3 bucket name did not match expected"
}

}
3 changes: 3 additions & 0 deletions terraform/tests/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "bucket_prefix" {
type = string
}

0 comments on commit f09d129

Please sign in to comment.