SlideShare a Scribd company logo
1 of 138
Download to read offline
Copyright © 2020 HashiCorp
Head in the Clouds: Testing
Infrastructure-as-Code
Config Management Camp 2020
Peter Souter
Sr. Technical Account Manager - HashiCorp
Introductions
Who is this bloke?
Technical Account Manager at HashiCorp
Peter Souter
Based in...
London, UK
This is my 6th CfgMgmentCamp!
Been coming since 2014 (missed 2018 - 👶)
Worn a lot of hats in my time...
Developer, Consultant, Pre-Sales, TAM
Interested in...
Making people’s operational life easier and
more secure
DEVOPS ALL THE THINGS
What are we here to talk about?
Config Management Camp 2020
Infrastructure-as-code
Treating the tooling that manages
your infrastructure with the same
way you would treat any other
code.
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
“Why should we test our
infrastructure as code anyways?”
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
1. Easy to regenerate from scratch
2. Code review and collaboration
3. Easier to conceptualise as a code model
4. Auditing and policies
5. Iteratively improve over time
6. Modularise, reuse and hide complexity
7. Testing
Qui bono?
Who benefits?
“The concern of velocity loss of added testing is very much
worthwhile in my experience. It’s why we have a known, stable
configuration and deployment codebase and can move on to more
relevant business problems. In their absence, I’ve without
exception had to firefight tooling, silent regressions, and human
error burning out teams and reducing confidence in automation
from across teams. Infrastructure as code without testing to me
is self-sabotage”
- Devon Kim, @djk29a, HashiConf 2019 Slack
Lets have
a brief history
lesson...
And before we start,
let me give my
caveats...
I’m not on the engineering team!
Nothing I say is gospel, nor can I
commit to any future roadmap
Configuration management tools install and
manage software on a machine that already
exists. Terraform is not a configuration
management tool, and it allows existing
tooling to focus on their strengths:
bootstrapping and initializing resources.
- https://www.terraform.io/intro/vs/chef-puppet.html
Config Management Camp 2020?
Infra
“Pre-prod”
VM Lab
DA CLOUD
?
“How do we test the
cloud?”
Two types of people interested in
testing IaC and it’s interactions
with DA CLOUD: Producers and
Consumers
A little background on
testing...
https://martinfowler.com/articles/practical-test-pyramid.html
Unit Testing
Acceptance
Testing
Integration
Testing
The terraform seemed to
generate the environment
correctly last time I tried…
meh, ship it!
Let’s eat the cone from
the bottom...
Let's start with the
most simple “tests”...
Compiling/Type Checking
TERMINAL
Chef: Ruby syntax check
$ ruby -c my_cookbook_file.rb
Syntax OK!
TERMINAL
TERMINAL
Terraform: validate
$ terraform validate
Error: Unsupported block type
on main.tf line 30, in resource "aws_instance" "foobar":
30: tags {
Blocks of type "tags" are not expected here. Did you mean to define argument "tags"?
If so, use the equals sign to assign it a value.
TERMINAL
TERMINAL
Ansible: --check
$ ansible-playbook apache.yml --check
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator
TERMINAL
TERMINAL
Puppet: parser validate
$ puppet parser validate
Error: Could not parse for environment production:
Syntax error at 'owner' at /tmp/foo.pp:5:5
TERMINAL
Linting
Terraform: tflint
TERMINAL
$ tflint
1 issue(s) found:
Error: instance_type is not a valid value (aws_instance_invalid_type)
on main.tf line 28:
28: instance_type = "t9.micro"
https://github.com/wata727/tflint
Chef: foodcritic
TERMINAL
$ foodcritic -C ./cookbooks/mysql
cookbooks/<cookbook Name>/attributes/server.rb
FC002: Avoid string interpolation where not required
85| default['<Cookbook Name>']['conf_dir'] = "#{mysql['basedir']}"
https://docs.chef.io/foodcritic.html
Puppet: puppet-lint
TERMINAL
$ puppet-lint /etc/puppet/modules
foo/manifests/bar.pp - ERROR: trailing whitespace found on line 1
apache/manifests/server.pp - WARNING: variable not enclosed in {} on line 56
http://puppet-lint.com/
Ansible: ansible-lint
TERMINAL
$ ansible-lint geerlingguy.apache
[ANSIBLE0013] Use shell only when shell functionality is required
/Users/chouseknecht/.ansible/roles/geerlingguy.apache/tasks/main.yml:19
Task/Handler: Get installed version of Apache.
[ANSIBLE0011] All tasks should be named
/Users/chouseknecht/.ansible/roles/geerlingguy.apache/tasks/main.yml:29
Task/Handler: include_vars apache-22.yml
https://docs.ansible.com/ansible-lint/
Ok, so now lets get deeper:
Unit Tests
Acceptance tests make sure that
you're building the right thing
Unit tests make sure that you're
building the thing right
https://stackoverflow.com/questions/4139095/unit-tests-vs-acceptance-tests
Red
Green
Refactor
A unit tests is for the logic you have
written, not to test the language
Don’t just write
tautological unit tests,
test the edge cases
Producers and consumers
have different intents for
unit-tests
Puppet - https://rspec-puppet.com/
TERMINAL
context 'repo enabled' do
context 'on CentOS' do
let(:facts) do
{
:operatingsystem => 'CentOS',
}
end
let(:params) {{ 'manage_repo' => true }}
it { is_expected.to contain_class('fish::Repo::Centos')}
it do
is_expected.to contain_yumrepo('shells_fish_release_2').with(
:descr => 'Fish shell - 2.x release series (CentOS_7)',
:baseurl => 'https://download.opensuse.org/repositories/shells:/fish:/release:/2/CentOS_7/',
:enabled => '1',
:gpgcheck => '1',
:gpgkey => "https://download.opensuse.org/repositories/shells:/fish:/release:/2/CentOS_7/repodata/repomd.xml.key",
)
end
end
Chef - https://docs.chef.io/chefspec.html
TERMINAL
context 'amazonlinux' do
cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'amazon', version: '2018.03').converge(described_recipe) }
it 'creates yum_repository[amzn-main]' do
expect(chef_run).to create_yum_repository('amzn-main')
end
it 'creates yum_repository[amzn-main-debuginfo]' do
expect(chef_run).to create_yum_repository('amzn-main-debuginfo')
end
it 'creates yum_repository[amzn-nosrc]' do
expect(chef_run).to create_yum_repository('amzn-nosrc')
end
end
Unit testing for Terraform:
Nothing official yet...
The Future…
Core Unit Testing?
https://github.com/hashicorp/terraform/issues/21628
Possibly… but we have a big backlog!
In the meantime, some
possible contenders...
clarity
https://github.com/xchapter7x/clarity/tree
▪ Self-contained binary
▪ Gherkin style features
▪ Behaviour-Driven Development
▪ Parses HCL for running its checks
▪ Provides its own Terraform specific
matchers
clarity example
TERMINAL
$ clarity single_instance.feature
Feature: Single Instance in AWS
Scenario: Creation of a single AWS micro instance # single_instance.feature:3
Given Terraform # terraform.go:76 -> *Match
And a " aws_instance" of type " resource" # terraform.go:242 -> *Match
Then attribute " instance_type" equals "t1.micro" # terraform.go:351 -> *Match
And it occurs exactly 1 times # terraform.go:489 -> *Match
1 scenarios ( 1 passed)
4 steps (4 passed)
1.613589ms
terraform-compliance
https://github.com/eerkunt/terraform-compliance
▪ Python CLI application
▪ Gherkin style features
▪ Behaviour-Driven Development
▪ Parses plan outputs for it’s checks
▪ Provides its own Terraform specific
matchers
terraform-compliance example
TERMINAL
$ terraform-compliance -p plan.out -f terraform_compliance/
terraform-compliance v1.0.51 initiated
Scenario Outline: Ensure that specific tags are defined
Given I have resource that supports tags defined
When it contains tags
Then it must contain <tags>
And its value must match the "<value>" regex
Examples:
| tags | value |
| Name | .+ |
1 features (1 passed)
1 scenarios (1 passed)
4 steps (4 passed)
Run 1570975178 finished within a moment
terraform_validate
https://github.com/elmundio87/terraform_validate
▪ Written as Python
▪ Standard unit testing
▪ Parses HCL for it’s checks
▪ Provides it’s own Terraform
specific matchers
terraform_validate example
TERMINAL
$ python3 test/*.py
+ terraform_validate
======================================================================
FAIL: test_tags (__main__.TestResources)
Checks resources for required tags.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/terraform_validate_tests.py", line 27, in test_tags
should_have_properties(required_tags)
File
"/usr/local/lib/python3.7/site-packages/terraform_validate/terraform_validate.py",
line 207, in should_have_properties
raise AssertionError("n".join(sorted(errors)))
AssertionError: [ aws_instance.foobar.tags] should have property: 'Date'
----------------------------------------------------------------------
Ran 1 test in 0.031s
FAILED (failures=1)
Pros
Fast to run
Easy to write
No environment or
credentials required
Cons
Doesn’t test actual outcome
IaC Unit
Testing
Ok, now the hard part:
Integration and Acceptance
People use
them interchangeably...
https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test
Acceptance tests are an external client that encompasses
enough information on how to drive the system under test (SUT)
in order to bring it to the point of asserting something.
Integration tests on the other hand, are used for testing the
internals of the system and are geared towards validating
contracts between modules of code.
http://blog.jonasbandi.net/2010/09/acceptance-vs-integration-tests.html
Either way:
How can we test against
“DA CLOUD”, something we don’t
directly control?
Approach 1:
Mock the API’s with fixtures
https://docs.pytest.org/en/latest/fixture.html
The purpose of test fixtures
is to provide a fixed baseline
upon which tests can reliably
and repeatedly execute.
These are often
pretty close to unit tests...
ACME Provider (Lets Encrypt)
https://www.terraform.io/docs/providers/acme/index.html
▪ We don’t want to fire
requests at a real ACME
CA provider
▪ Instead use a fixture
▪ Golang httptest
ACME Provider - Fixture mocking example
ACME Provider - Fixture mocking example
Pros
No dependency on cloud
Quick to run
Cons
Can be a lot of work to
maintain fixtures
Won’t test drift or changes in
actual cloud
Fixture
Mocking
Approach 2:
Simulated Cloud
With the rise of Serverless/Lamba
frameworks, devs needed
something local to test against and
people started making Cloud
Simulators
Azurite
https://docs.microsoft.com/en-us/azure/storage/co
mmon/storage-use-azurite
DynamoDB Local
https://docs.aws.amazon.com/amazondynamodb/l
atest/developerguide/DynamoDBLocal.html
GCP Emulator
https://cloud.google.com/sdk/gcloud/reference/be
ta/emulators/
Localstack
https://localstack.cloud
▪ “Cloud in a box”
▪ Can run in Docker
▪ Provides real working
versions of AWS APIs
🚨
Live
Demo
Warning!
🚨
Pros
No dependency on cloud
More debugging and “real
life” experience than a
mocked service
Cons
Won’t exist for every service
Relies on simulated service
to keep in line with real
cloud
Still not _really_ testing an
actual Cloud service
Fixture
Mocking
Approach 3:
Don’t mock anything, do it for real!
Pull-request acceptance tests for Azure Provider
Full Suite example for Azure Provider:
Full Suite example for Azure Provider:
From a producer point of view,
you’re testing the tool
As a consumer, you probably want
an integration test of your real full
stack of pieces
Ultimately,
you care
about state
terratest
https://github.com/gruntwork-io/terratest
▪ Full acceptance framework for
Terraform
▪ Developed by Gruntworks
▪ Used to test large module
deployments
▪ Written in Golang
▪ Helper methods for validating
state
At Gruntwork we test dozens of modules with terratest. We have
hooks to CircleCI to run tests on each commit. For us, the ROI is
huge - we've caught many regressions & problems thanks to
the tests.
It can definitely result in long test times. In some of our larger
repos, test can take 45-60 minutes. What I normally do is
add/update a test, run just that test locally to make sure it's
working, then let the full suite run in CircleCI.
- Ben Whaley, Gruntworks, HashiConf 2020 Slack
terratest example
TERMINAL
$ go test -v test/terraform_basic_example_test.go
=== RUN TestTerraformAWSInstanceType
=== PAUSE TestTerraformAWSInstanceType
=== CONT TestTerraformAWSInstanceType
TestTerraformAWSInstanceType 2020-10-13T16:09:10+01:00 retry.go:72: terraform [init -upgrade=false]
TestTerraformAWSInstanceType 2020-10-13T16:09:10+01:00 command.go:87: Running command terraform with args
[init -upgrade=false]
TestTerraformAWSInstanceType 2020-10-13T16:09:21+01:00 command.go:158: aws_instance.foobar: Creating...
TestTerraformAWSInstanceType 2020-10-13T16:09:31+01:00 command.go:158: aws_instance.foobar: Still
creating... [10s elapsed]
TestTerraformAWSInstanceType 2020-10-13T16:09:41+01:00 command.go:158: aws_instance.foobar: Still
creating... [20s elapsed]
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: aws_instance.foobar: Creation
complete after 21s [id=i-08d65b4371c14fc4e]
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158:
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: Apply complete! Resources: 1
added, 0 changed, 0 destroyed.
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158:
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: Outputs:
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158:
TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: instance_type = t1.micro
ok command-line-arguments 84.607s
Cons
Slower
Can be Costly
Can interfere with real
infrastructure
Pros
End-to-end testing
Interacts with real APIs
Closest to the real thing
Acceptance
and
Integration
Testing
Beyond conventional
testing...
Observability
Not going to go too deeply
into this...
Is it working beyond our
test suite?
https://www.weave.works/blog/gitops-part-3-observability
For more information...
https://www.youtube.com/watch?v=fOdtgHu_KeA&list=PLgeeFA2rwFRMIblCQi_8BkXyZALQSjSSO&index=3&t=0s
From Cfgmgmtcamp 2019
Governance
Every organisation has policies
Naming conventions, tagging, price
guides, cost centres and limits, legal
requirements and regulations etc.
Generally under the umbrella of
Governance
If we can reflect
Policies-as-code
we get the same
benefits we get from
Infrastructure-as-code
HashiCorp Sentinel
https://www.hashicorp.com/sentinel/
“An embeddable policy as code
framework to enable fine-grained,
logic-based policy decisions that can
be extended to source external
information to make decisions.”
TERMINAL
Sentinel example for Terraform
CODE EDITOR
import "tfplan"
main = rule {
all tfplan.resources.aws_security_group as _, instances {
all instances as _, sg {
all sg.applied.egress as egress {
egress.cidr_blocks not contains "0.0.0.0/0"
}
}
🚨
Live
Demo
Warning
🚨
What have we learnt?
The benefits of testing IaC
Regardless of what tool you’re using, Infrastructure-as-code without testing
is “self-sabotage”
Unit Testing for IaC
Allowing quick feedback loops and TDD
Acceptance and Integration testing for IaC
Allowing you assurance that your IaC final state reflects what you expect
Beyond conventional testing
Using observability to check things are running ok after deployment...
The benefits of Policy-as-code
How reflecting organisational governance as PoC can speed up deployment
Thank You
psouter@hashicorp.com
@petersouter
www.hashicorp.com
13
8

More Related Content

What's hot

Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Toru Furukawa
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)Robert Swisher
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr VronskiyFwdays
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksCarlos Sanchez
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Eric Phan
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetKubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetPer Bernhardt
 
Minimal MVC in JavaScript
Minimal MVC in JavaScriptMinimal MVC in JavaScript
Minimal MVC in JavaScriptMosky Liu
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To SwiftJohn Anderson
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
PostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consulPostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consulSean Chittenden
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices Nebulaworks
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHPPer Bernhardt
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmusBram Vogelaar
 

What's hot (20)

Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitetKubernetes: Wie Chefkoch.de mit Containern arbeitet
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
 
Minimal MVC in JavaScript
Minimal MVC in JavaScriptMinimal MVC in JavaScript
Minimal MVC in JavaScript
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
PostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consulPostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consul
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
Node.js cluster
Node.js clusterNode.js cluster
Node.js cluster
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHP
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 

Similar to Head in the Clouds: Testing Infra as Code - Config Management 2020

End to End immutable infrastructure testing
End to End immutable infrastructure testingEnd to End immutable infrastructure testing
End to End immutable infrastructure testingNebulaworks
 
Test Driven Development with Chef
Test Driven Development with ChefTest Driven Development with Chef
Test Driven Development with ChefSimone Soldateschi
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalkHiroshi SHIBATA
 
Winning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleWinning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleRusty Klophaus
 
PHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpPHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpAhmed Abdou
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewAl Sargent
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to TestZsolt Fabok
 
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07garrett honeycutt
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroSteven Pignataro
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Codeeddiehaber
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareLaura Frank Tacho
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric SystemErin Dees
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Yan Cui
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryJames Wickett
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Yan Cui
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)James Titcumb
 
Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017adamleff
 

Similar to Head in the Clouds: Testing Infra as Code - Config Management 2020 (20)

End to End immutable infrastructure testing
End to End immutable infrastructure testingEnd to End immutable infrastructure testing
End to End immutable infrastructure testing
 
Test Driven Development with Chef
Test Driven Development with ChefTest Driven Development with Chef
Test Driven Development with Chef
 
20141210 rakuten techtalk
20141210 rakuten techtalk20141210 rakuten techtalk
20141210 rakuten techtalk
 
Winning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test CycleWinning the Erlang Edit•Build•Test Cycle
Winning the Erlang Edit•Build•Test Cycle
 
PHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in phpPHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in php
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program Overview
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
 
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your Software
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous Delivery
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
 
Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017Compliance Automation with InSpec - Chef NYC Meetup - April 2017
Compliance Automation with InSpec - Chef NYC Meetup - April 2017
 

More from Peter Souter

I don't know what I'm Doing: A newbie guide for Golang for DevOps
I don't know what I'm Doing: A newbie guide for Golang for DevOpsI don't know what I'm Doing: A newbie guide for Golang for DevOps
I don't know what I'm Doing: A newbie guide for Golang for DevOpsPeter Souter
 
Consul Connect - EPAM SEC - 22nd september 2018
Consul Connect - EPAM SEC - 22nd september 2018Consul Connect - EPAM SEC - 22nd september 2018
Consul Connect - EPAM SEC - 22nd september 2018Peter Souter
 
Maintaining Layer 8
Maintaining Layer 8Maintaining Layer 8
Maintaining Layer 8Peter Souter
 
Knee deep in the undef - Tales from refactoring old Puppet codebases
Knee deep in the undef  - Tales from refactoring old Puppet codebasesKnee deep in the undef  - Tales from refactoring old Puppet codebases
Knee deep in the undef - Tales from refactoring old Puppet codebasesPeter Souter
 
Compliance and auditing with Puppet
Compliance and auditing with PuppetCompliance and auditing with Puppet
Compliance and auditing with PuppetPeter Souter
 
Hardening Your Config Management - Security and Attack Vectors in Config Mana...
Hardening Your Config Management - Security and Attack Vectors in Config Mana...Hardening Your Config Management - Security and Attack Vectors in Config Mana...
Hardening Your Config Management - Security and Attack Vectors in Config Mana...Peter Souter
 
Puppet module anti patterns
Puppet module anti patternsPuppet module anti patterns
Puppet module anti patternsPeter Souter
 
Little Puppet Tools To Make Your Life Better
Little Puppet Tools To Make Your Life BetterLittle Puppet Tools To Make Your Life Better
Little Puppet Tools To Make Your Life BetterPeter Souter
 
Testing servers like software
Testing servers like softwareTesting servers like software
Testing servers like softwarePeter Souter
 

More from Peter Souter (10)

I don't know what I'm Doing: A newbie guide for Golang for DevOps
I don't know what I'm Doing: A newbie guide for Golang for DevOpsI don't know what I'm Doing: A newbie guide for Golang for DevOps
I don't know what I'm Doing: A newbie guide for Golang for DevOps
 
Consul Connect - EPAM SEC - 22nd september 2018
Consul Connect - EPAM SEC - 22nd september 2018Consul Connect - EPAM SEC - 22nd september 2018
Consul Connect - EPAM SEC - 22nd september 2018
 
Maintaining Layer 8
Maintaining Layer 8Maintaining Layer 8
Maintaining Layer 8
 
Knee deep in the undef - Tales from refactoring old Puppet codebases
Knee deep in the undef  - Tales from refactoring old Puppet codebasesKnee deep in the undef  - Tales from refactoring old Puppet codebases
Knee deep in the undef - Tales from refactoring old Puppet codebases
 
Compliance and auditing with Puppet
Compliance and auditing with PuppetCompliance and auditing with Puppet
Compliance and auditing with Puppet
 
Lock it down
Lock it downLock it down
Lock it down
 
Hardening Your Config Management - Security and Attack Vectors in Config Mana...
Hardening Your Config Management - Security and Attack Vectors in Config Mana...Hardening Your Config Management - Security and Attack Vectors in Config Mana...
Hardening Your Config Management - Security and Attack Vectors in Config Mana...
 
Puppet module anti patterns
Puppet module anti patternsPuppet module anti patterns
Puppet module anti patterns
 
Little Puppet Tools To Make Your Life Better
Little Puppet Tools To Make Your Life BetterLittle Puppet Tools To Make Your Life Better
Little Puppet Tools To Make Your Life Better
 
Testing servers like software
Testing servers like softwareTesting servers like software
Testing servers like software
 

Recently uploaded

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfROWELL MARQUINA
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - AvrilIvanti
 

Recently uploaded (20)

The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - Avril
 

Head in the Clouds: Testing Infra as Code - Config Management 2020

  • 1. Copyright © 2020 HashiCorp Head in the Clouds: Testing Infrastructure-as-Code Config Management Camp 2020 Peter Souter Sr. Technical Account Manager - HashiCorp
  • 2. Introductions Who is this bloke? Technical Account Manager at HashiCorp Peter Souter Based in... London, UK This is my 6th CfgMgmentCamp! Been coming since 2014 (missed 2018 - 👶) Worn a lot of hats in my time... Developer, Consultant, Pre-Sales, TAM Interested in... Making people’s operational life easier and more secure DEVOPS ALL THE THINGS
  • 3. What are we here to talk about?
  • 6. Treating the tooling that manages your infrastructure with the same way you would treat any other code.
  • 7. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 8. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 9. “Why should we test our infrastructure as code anyways?”
  • 10. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 11. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 12. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 13. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 14. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 15. 1. Easy to regenerate from scratch 2. Code review and collaboration 3. Easier to conceptualise as a code model 4. Auditing and policies 5. Iteratively improve over time 6. Modularise, reuse and hide complexity 7. Testing Qui bono? Who benefits?
  • 16. “The concern of velocity loss of added testing is very much worthwhile in my experience. It’s why we have a known, stable configuration and deployment codebase and can move on to more relevant business problems. In their absence, I’ve without exception had to firefight tooling, silent regressions, and human error burning out teams and reducing confidence in automation from across teams. Infrastructure as code without testing to me is self-sabotage” - Devon Kim, @djk29a, HashiConf 2019 Slack
  • 17. Lets have a brief history lesson...
  • 18. And before we start, let me give my caveats...
  • 19. I’m not on the engineering team! Nothing I say is gospel, nor can I commit to any future roadmap
  • 20. Configuration management tools install and manage software on a machine that already exists. Terraform is not a configuration management tool, and it allows existing tooling to focus on their strengths: bootstrapping and initializing resources. - https://www.terraform.io/intro/vs/chef-puppet.html
  • 21. Config Management Camp 2020? Infra
  • 22.
  • 23.
  • 26.
  • 28.
  • 29.
  • 30. ?
  • 31.
  • 32.
  • 33. “How do we test the cloud?”
  • 34. Two types of people interested in testing IaC and it’s interactions with DA CLOUD: Producers and Consumers
  • 35. A little background on testing...
  • 38.
  • 39. The terraform seemed to generate the environment correctly last time I tried… meh, ship it!
  • 40. Let’s eat the cone from the bottom...
  • 41.
  • 42. Let's start with the most simple “tests”...
  • 44. TERMINAL Chef: Ruby syntax check $ ruby -c my_cookbook_file.rb Syntax OK! TERMINAL
  • 45. TERMINAL Terraform: validate $ terraform validate Error: Unsupported block type on main.tf line 30, in resource "aws_instance" "foobar": 30: tags { Blocks of type "tags" are not expected here. Did you mean to define argument "tags"? If so, use the equals sign to assign it a value. TERMINAL
  • 46. TERMINAL Ansible: --check $ ansible-playbook apache.yml --check ERROR! Syntax Error while loading YAML. did not find expected '-' indicator TERMINAL
  • 47. TERMINAL Puppet: parser validate $ puppet parser validate Error: Could not parse for environment production: Syntax error at 'owner' at /tmp/foo.pp:5:5 TERMINAL
  • 49. Terraform: tflint TERMINAL $ tflint 1 issue(s) found: Error: instance_type is not a valid value (aws_instance_invalid_type) on main.tf line 28: 28: instance_type = "t9.micro" https://github.com/wata727/tflint
  • 50. Chef: foodcritic TERMINAL $ foodcritic -C ./cookbooks/mysql cookbooks/<cookbook Name>/attributes/server.rb FC002: Avoid string interpolation where not required 85| default['<Cookbook Name>']['conf_dir'] = "#{mysql['basedir']}" https://docs.chef.io/foodcritic.html
  • 51. Puppet: puppet-lint TERMINAL $ puppet-lint /etc/puppet/modules foo/manifests/bar.pp - ERROR: trailing whitespace found on line 1 apache/manifests/server.pp - WARNING: variable not enclosed in {} on line 56 http://puppet-lint.com/
  • 52. Ansible: ansible-lint TERMINAL $ ansible-lint geerlingguy.apache [ANSIBLE0013] Use shell only when shell functionality is required /Users/chouseknecht/.ansible/roles/geerlingguy.apache/tasks/main.yml:19 Task/Handler: Get installed version of Apache. [ANSIBLE0011] All tasks should be named /Users/chouseknecht/.ansible/roles/geerlingguy.apache/tasks/main.yml:29 Task/Handler: include_vars apache-22.yml https://docs.ansible.com/ansible-lint/
  • 53. Ok, so now lets get deeper: Unit Tests
  • 54. Acceptance tests make sure that you're building the right thing Unit tests make sure that you're building the thing right https://stackoverflow.com/questions/4139095/unit-tests-vs-acceptance-tests
  • 55.
  • 57. A unit tests is for the logic you have written, not to test the language
  • 58. Don’t just write tautological unit tests, test the edge cases
  • 59. Producers and consumers have different intents for unit-tests
  • 60. Puppet - https://rspec-puppet.com/ TERMINAL context 'repo enabled' do context 'on CentOS' do let(:facts) do { :operatingsystem => 'CentOS', } end let(:params) {{ 'manage_repo' => true }} it { is_expected.to contain_class('fish::Repo::Centos')} it do is_expected.to contain_yumrepo('shells_fish_release_2').with( :descr => 'Fish shell - 2.x release series (CentOS_7)', :baseurl => 'https://download.opensuse.org/repositories/shells:/fish:/release:/2/CentOS_7/', :enabled => '1', :gpgcheck => '1', :gpgkey => "https://download.opensuse.org/repositories/shells:/fish:/release:/2/CentOS_7/repodata/repomd.xml.key", ) end end
  • 61. Chef - https://docs.chef.io/chefspec.html TERMINAL context 'amazonlinux' do cached(:chef_run) { ChefSpec::SoloRunner.new(platform: 'amazon', version: '2018.03').converge(described_recipe) } it 'creates yum_repository[amzn-main]' do expect(chef_run).to create_yum_repository('amzn-main') end it 'creates yum_repository[amzn-main-debuginfo]' do expect(chef_run).to create_yum_repository('amzn-main-debuginfo') end it 'creates yum_repository[amzn-nosrc]' do expect(chef_run).to create_yum_repository('amzn-nosrc') end end
  • 62. Unit testing for Terraform: Nothing official yet...
  • 63. The Future… Core Unit Testing? https://github.com/hashicorp/terraform/issues/21628
  • 64. Possibly… but we have a big backlog!
  • 65. In the meantime, some possible contenders...
  • 66. clarity https://github.com/xchapter7x/clarity/tree ▪ Self-contained binary ▪ Gherkin style features ▪ Behaviour-Driven Development ▪ Parses HCL for running its checks ▪ Provides its own Terraform specific matchers
  • 67. clarity example TERMINAL $ clarity single_instance.feature Feature: Single Instance in AWS Scenario: Creation of a single AWS micro instance # single_instance.feature:3 Given Terraform # terraform.go:76 -> *Match And a " aws_instance" of type " resource" # terraform.go:242 -> *Match Then attribute " instance_type" equals "t1.micro" # terraform.go:351 -> *Match And it occurs exactly 1 times # terraform.go:489 -> *Match 1 scenarios ( 1 passed) 4 steps (4 passed) 1.613589ms
  • 68. terraform-compliance https://github.com/eerkunt/terraform-compliance ▪ Python CLI application ▪ Gherkin style features ▪ Behaviour-Driven Development ▪ Parses plan outputs for it’s checks ▪ Provides its own Terraform specific matchers
  • 69. terraform-compliance example TERMINAL $ terraform-compliance -p plan.out -f terraform_compliance/ terraform-compliance v1.0.51 initiated Scenario Outline: Ensure that specific tags are defined Given I have resource that supports tags defined When it contains tags Then it must contain <tags> And its value must match the "<value>" regex Examples: | tags | value | | Name | .+ | 1 features (1 passed) 1 scenarios (1 passed) 4 steps (4 passed) Run 1570975178 finished within a moment
  • 70. terraform_validate https://github.com/elmundio87/terraform_validate ▪ Written as Python ▪ Standard unit testing ▪ Parses HCL for it’s checks ▪ Provides it’s own Terraform specific matchers
  • 71. terraform_validate example TERMINAL $ python3 test/*.py + terraform_validate ====================================================================== FAIL: test_tags (__main__.TestResources) Checks resources for required tags. ---------------------------------------------------------------------- Traceback (most recent call last): File "test/terraform_validate_tests.py", line 27, in test_tags should_have_properties(required_tags) File "/usr/local/lib/python3.7/site-packages/terraform_validate/terraform_validate.py", line 207, in should_have_properties raise AssertionError("n".join(sorted(errors))) AssertionError: [ aws_instance.foobar.tags] should have property: 'Date' ---------------------------------------------------------------------- Ran 1 test in 0.031s FAILED (failures=1)
  • 72. Pros Fast to run Easy to write No environment or credentials required Cons Doesn’t test actual outcome IaC Unit Testing
  • 73. Ok, now the hard part: Integration and Acceptance
  • 75. https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test Acceptance tests are an external client that encompasses enough information on how to drive the system under test (SUT) in order to bring it to the point of asserting something. Integration tests on the other hand, are used for testing the internals of the system and are geared towards validating contracts between modules of code.
  • 77. Either way: How can we test against “DA CLOUD”, something we don’t directly control?
  • 78. Approach 1: Mock the API’s with fixtures
  • 79. https://docs.pytest.org/en/latest/fixture.html The purpose of test fixtures is to provide a fixed baseline upon which tests can reliably and repeatedly execute.
  • 80. These are often pretty close to unit tests...
  • 81. ACME Provider (Lets Encrypt) https://www.terraform.io/docs/providers/acme/index.html ▪ We don’t want to fire requests at a real ACME CA provider ▪ Instead use a fixture ▪ Golang httptest
  • 82. ACME Provider - Fixture mocking example
  • 83. ACME Provider - Fixture mocking example
  • 84. Pros No dependency on cloud Quick to run Cons Can be a lot of work to maintain fixtures Won’t test drift or changes in actual cloud Fixture Mocking
  • 86. With the rise of Serverless/Lamba frameworks, devs needed something local to test against and people started making Cloud Simulators
  • 88. Localstack https://localstack.cloud ▪ “Cloud in a box” ▪ Can run in Docker ▪ Provides real working versions of AWS APIs
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97. Pros No dependency on cloud More debugging and “real life” experience than a mocked service Cons Won’t exist for every service Relies on simulated service to keep in line with real cloud Still not _really_ testing an actual Cloud service Fixture Mocking
  • 98. Approach 3: Don’t mock anything, do it for real!
  • 99.
  • 100.
  • 101.
  • 102.
  • 103. Pull-request acceptance tests for Azure Provider
  • 104. Full Suite example for Azure Provider:
  • 105. Full Suite example for Azure Provider:
  • 106.
  • 107. From a producer point of view, you’re testing the tool
  • 108. As a consumer, you probably want an integration test of your real full stack of pieces
  • 110. terratest https://github.com/gruntwork-io/terratest ▪ Full acceptance framework for Terraform ▪ Developed by Gruntworks ▪ Used to test large module deployments ▪ Written in Golang ▪ Helper methods for validating state
  • 111. At Gruntwork we test dozens of modules with terratest. We have hooks to CircleCI to run tests on each commit. For us, the ROI is huge - we've caught many regressions & problems thanks to the tests. It can definitely result in long test times. In some of our larger repos, test can take 45-60 minutes. What I normally do is add/update a test, run just that test locally to make sure it's working, then let the full suite run in CircleCI. - Ben Whaley, Gruntworks, HashiConf 2020 Slack
  • 112. terratest example TERMINAL $ go test -v test/terraform_basic_example_test.go === RUN TestTerraformAWSInstanceType === PAUSE TestTerraformAWSInstanceType === CONT TestTerraformAWSInstanceType TestTerraformAWSInstanceType 2020-10-13T16:09:10+01:00 retry.go:72: terraform [init -upgrade=false] TestTerraformAWSInstanceType 2020-10-13T16:09:10+01:00 command.go:87: Running command terraform with args [init -upgrade=false] TestTerraformAWSInstanceType 2020-10-13T16:09:21+01:00 command.go:158: aws_instance.foobar: Creating... TestTerraformAWSInstanceType 2020-10-13T16:09:31+01:00 command.go:158: aws_instance.foobar: Still creating... [10s elapsed] TestTerraformAWSInstanceType 2020-10-13T16:09:41+01:00 command.go:158: aws_instance.foobar: Still creating... [20s elapsed] TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: aws_instance.foobar: Creation complete after 21s [id=i-08d65b4371c14fc4e] TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: Apply complete! Resources: 1 added, 0 changed, 0 destroyed. TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: Outputs: TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: TestTerraformAWSInstanceType 2020-10-13T16:09:43+01:00 command.go:158: instance_type = t1.micro ok command-line-arguments 84.607s
  • 113. Cons Slower Can be Costly Can interfere with real infrastructure Pros End-to-end testing Interacts with real APIs Closest to the real thing Acceptance and Integration Testing
  • 116. Not going to go too deeply into this...
  • 117.
  • 118. Is it working beyond our test suite?
  • 122. Every organisation has policies Naming conventions, tagging, price guides, cost centres and limits, legal requirements and regulations etc. Generally under the umbrella of Governance
  • 123.
  • 124. If we can reflect Policies-as-code we get the same benefits we get from Infrastructure-as-code
  • 125. HashiCorp Sentinel https://www.hashicorp.com/sentinel/ “An embeddable policy as code framework to enable fine-grained, logic-based policy decisions that can be extended to source external information to make decisions.”
  • 126. TERMINAL Sentinel example for Terraform CODE EDITOR import "tfplan" main = rule { all tfplan.resources.aws_security_group as _, instances { all instances as _, sg { all sg.applied.egress as egress { egress.cidr_blocks not contains "0.0.0.0/0" } }
  • 128.
  • 129.
  • 130.
  • 131.
  • 132. What have we learnt?
  • 133. The benefits of testing IaC Regardless of what tool you’re using, Infrastructure-as-code without testing is “self-sabotage”
  • 134. Unit Testing for IaC Allowing quick feedback loops and TDD
  • 135. Acceptance and Integration testing for IaC Allowing you assurance that your IaC final state reflects what you expect
  • 136. Beyond conventional testing Using observability to check things are running ok after deployment...
  • 137. The benefits of Policy-as-code How reflecting organisational governance as PoC can speed up deployment