thiagonache / terraformtest Goto Github PK
View Code? Open in Web Editor NEWEasier way to unit test terraform
License: MIT License
Easier way to unit test terraform
License: MIT License
The Tf is already conveyed by the terraformtest prefix.
Data for tests shouldn't be in the same directory as the code. The two terraform plan files should be moved to a new directory called testdata.
I want to reduce the paperwork required to run a test. Eg.:
tfPlan, err := terraformtest.ReadPlan("./mymodule.plan.json")
if err != nil {
t.Fatalf("Cannot read plan file ./mymodule.plan.json: %v", err)
}
wantResource := terraformtest.Resource{
Address: "module.vpc.aws_vpc.this[0]",
Metadata: map[string]string{
"type": "aws_vpc",
"name": "this",
},
Values: map[string]string{
"enable_dns_hostnames": "true",
"enable_dns_support": "true",
"assign_generated_ipv6_cidr_block": "false",
"cidr_block": "10.0.0.0/16",
"instance_tenancy": "default",
},
}
gotRS := tfPlan.Resources
if !gotRS.Contains(wantResource) {
t.Error(gotRS.Diff())
}
Could be simplified to
wantResource := terraformtest.Resource{
Address: "module.vpc.aws_vpc.this[0]",
Metadata: map[string]string{
"type": "aws_vpc",
"name": "this",
},
Values: map[string]string{
"enable_dns_hostnames": "true",
"enable_dns_support": "true",
"assign_generated_ipv6_cidr_block": "false",
"cidr_block": "10.0.0.0/16",
"instance_tenancy": "default",
},
}
r := terraformtest.New(
terraformtest.WithPlanFile("./mymodule.plan.json")
)
terraformtest.Contains(wantResource)
Depends on #3.
The test function ReadPlanFile should Fatal instead of Error since nothing can be done if it cannot read the file.
Also, we should update from wantBiggerThan := 2000
to want := the exact number of bytes
.
Currently we can only test values but we may want to test some variables.
{
"variables": {
}
}
The transform function should also store the values inside of this block into the type Resource which will need an extra field probably called Variables which is going to be a map[string]string.
The functions Contains and Equal should be modified to consider the new data.
Please, also add respective tests for the new function ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.