Skip to content

Commit 74170d8

Browse files
authored
Merge pull request microsoft#46 from aheumaier/samples/compliance-testing
Samples/compliance testing
2 parents e4058ef + 8d795d5 commit 74170d8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

samples/compliance-testing/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Terraform Compliance Testing
1+
# Tutorial: Terraform Compliance Testing
22

33
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.
44

@@ -17,7 +17,7 @@ One of the problems you might have in your team is environments getting hosed wh
1717

1818
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.
1919

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.
2121

2222
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.
2323

@@ -76,14 +76,14 @@ Scenario Outline: Ensure that specific tags are defined
7676
Examples:
7777
| tags | value |
7878
| Creator | .+ |
79-
| application | .+ |
80-
| role | .+ |
81-
| environment | ^(prod\|uat\|dev)$ |
79+
| Application | .+ |
80+
| Role | .+ |
81+
| Environment | ^(prod\|uat\|dev)$ |
8282
```
8383

8484
## How-to run this example
8585

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.
8787

8888
After checkout the repo ...
8989

@@ -109,7 +109,7 @@ docker run --rm -v $PWD:/target -it eerkunt/terraform-compliance -f features -p
109109

110110
### From Red to Green
111111

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:
113113

114114
![tf-compliance-run-tagging-fail](assets/tf-compliance-run-tagging-fail.png)
115115

@@ -120,7 +120,7 @@ Make the test green again by adding all required tags to `main.tf`:
120120
Environment = "dev"
121121
Application = "Azure Compliance"
122122
Creator = "Azure Compliance"
123-
Version = "Azure Compliance"
123+
Role = "Azure Compliance"
124124
}
125125
126126
```
@@ -132,6 +132,7 @@ terraform validate
132132
terraform plan -out tf.out
133133
```
134134

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:
136136

137137
![tf-compliance-run-tagging-succeed](assets/tf-compliance-run-tagging-succeed.png)
138+

0 commit comments

Comments
 (0)