You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/compliance-testing/README.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Terraform Compliance Testing
1
+
# Tutorial: Terraform Compliance Testing
2
2
3
3
Compliance testing, also known as Conformance testing, is a nonfunctional testing technique which is done to validate whether the system developed meets the organization’s prescribed standards or not. Most software teams do an analysis to check that the standards are properly enforced and implemented. Often working simultaneously to improve the standards, which will, in turn, lead to better quality.
4
4
@@ -17,7 +17,7 @@ One of the problems you might have in your team is environments getting hosed wh
17
17
18
18
An obvious response could be to call out a policy to require tags on resources where applicable and add a `role` and `creator` tag to the resource that is deployed. [Terraform-compliance](https://terraform-compliance.com) is a tool that helps you with that. It mainly focuses on negative testing instead of having fully-fledged functional tests that are mostly used for proving a component of code is performing properly.
19
19
20
-
Fortunately, `terraform` is a marvellous abstraction layer for any API that creates/updates/destroys entities. `Terraform` also provides the capability to ensure everything is up-to-date between the local configuration and the remote API(s) responses. Since `terraform` is mostly used against Cloud APIs we still miss a way to ensure the code deployed against the infrastructure must follow specific policies - like HashiCorp currently provides with `Sentinel` for Enterprise Products. `Terraform-compliance` is providing a similar functionality only for terraform while it is free-to-use and it is Open Source.
20
+
Fortunately, `terraform` is a marvellous abstraction layer for any API that creates/updates/destroys entities. `Terraform` also provides the capability to ensure everything is up-to-date between the local configuration and the remote API(s) responses. Since `terraform` is mostly used against Cloud APIs we still miss a way to ensure the code deployed against the infrastructure must follow specific policies - like HashiCorp currently provides with [Sentinel](https://docs.hashicorp.com/sentinel/intro/what/) for Enterprise Products. `Terraform-compliance` is providing a similar functionality only for terraform while it is free-to-use and it is Open Source.
21
21
22
22
A sample compliance policy for the issue mentioned could be like this: `if you are working with Azure, you should not create a resource, without having any tags`.`Terraform-compliance` provides a test framework to create these policies that will be executed against your terraform plan file in a context where both developers and security teams can understand easily while reading it, by applying [Behaviour Driven Development](https://en.wikipedia.org/wiki/Behavior-driven_development) principles.
23
23
@@ -76,14 +76,14 @@ Scenario Outline: Ensure that specific tags are defined
76
76
Examples:
77
77
| tags | value |
78
78
| Creator | .+ |
79
-
| application | .+ |
80
-
| role | .+ |
81
-
| environment | ^(prod\|uat\|dev)$ |
79
+
| Application | .+ |
80
+
| Role | .+ |
81
+
| Environment | ^(prod\|uat\|dev)$ |
82
82
```
83
83
84
84
## How-to run this example
85
85
86
-
The example above is taken from the [github.com/terrraform-testing](https://github.com/LeagueOfExtraordinaryHackers/terraform-testing/tree/compliance-testing/examples/compliance-testing) repository.
86
+
The example above is taken from the [github.com/Azure/terrraform](https://github.com/Azure/terrraform/tree/compliance-testing/examples/master) repository.
87
87
88
88
After checkout the repo ...
89
89
@@ -109,7 +109,7 @@ docker run --rm -v $PWD:/target -it eerkunt/terraform-compliance -f features -p
109
109
110
110
### From Red to Green
111
111
112
-
This should result in a failing test run:
112
+
This should result in a failing test run. We see our first rule of requiring existence of tags suceed but we don't comply with the full spec of tags: `Role` and `Creator` tags are missing:
@@ -120,7 +120,7 @@ Make the test green again by adding all required tags to `main.tf`:
120
120
Environment = "dev"
121
121
Application = "Azure Compliance"
122
122
Creator = "Azure Compliance"
123
-
Version = "Azure Compliance"
123
+
Role = "Azure Compliance"
124
124
}
125
125
126
126
```
@@ -132,6 +132,7 @@ terraform validate
132
132
terraform plan -out tf.out
133
133
```
134
134
135
-
Now, we should be green when running the tests suite again:
135
+
Now, we should be green when running the tests suite again. We see our first rule of requiring existence of tags suceed and now we also provide the full spec of tags too:
0 commit comments