validating puppet managed resources in aws with awspec

25
Validating Puppet managed resources with awspec Get started with rspec testing for AWS resources Twitter: @dkcwd

Upload: dave-clark

Post on 16-Apr-2017

230 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Validating Puppet managed resources in AWS with awspec

Validating Puppet managed resources with awspecGet started with rspec testing for AWS resources

Twitter: @dkcwd

Page 2: Validating Puppet managed resources in AWS with awspec

First a little background….

Page 3: Validating Puppet managed resources in AWS with awspec

About this session When I talk about managing resources in AWS I’m talking about the servers and other services we are leveraging in AWS.

The concepts of testing resources, whether in AWS or not, is relevant regardless of whether you are using Puppet or not.

After the session, you know more about with the awspec library.

Page 4: Validating Puppet managed resources in AWS with awspec

About this session We have people of all levels of experience in this session.

Please feel free to share your knowledge and experience with the group and ask questions.

Page 5: Validating Puppet managed resources in AWS with awspec

Why test our resources?

?

Page 6: Validating Puppet managed resources in AWS with awspec

Why test our resources? Once the resources have been “spun up” and configured, the test suite can be run to verify resources are in line with expectations.

CI tools can alert the team to issues which need attention.

$$$ money can be saved….

Page 7: Validating Puppet managed resources in AWS with awspec

Why test our resources? Resource tests can be considered part of fulfilling a contract with the business.

Demonstrating the resources are ready could be as simple as ensuring the typical ports are exposed for a web server and that a page containing some specific text can be loaded within a specific timeframe.

Page 8: Validating Puppet managed resources in AWS with awspec

Why test our resources? In the context of managing your Software Development Life Cycle (SDLC)

Before we deploy an application to our infrastructure we want to know that the environment is correctly configured.

Unexpected behavior can result from leveraging configuration data which has been included in error.

Page 9: Validating Puppet managed resources in AWS with awspec

But Puppet describes the desired config!

Yes! And if you are using Hiera, you are likely to be including extra data conditionally

Sometimes people make mistakes….

Page 10: Validating Puppet managed resources in AWS with awspec

A hypothetical situation You’re managing your network settings with Puppet and you have conditionally configured the value of resolve.conf

The DNS settings which have been incorrectly supplied are appropriate for London when they should be settings which are appropriate for China.

Page 11: Validating Puppet managed resources in AWS with awspec

Ok, so let’s talk about awspec….

Page 12: Validating Puppet managed resources in AWS with awspec

Make sure you find the right library

https://github.com/k1LoW/awspec

Page 13: Validating Puppet managed resources in AWS with awspec

Based on Serverspechttps://github.com/k1LoW/awspec

Page 14: Validating Puppet managed resources in AWS with awspec

Some set up is required To become more familiar with awspec you should do the following:

Set up an AWS account for testing Set up an IAM user, noting the access key and secret access key Install the AWS tools and run the ``aws configure`` command

See: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Page 15: Validating Puppet managed resources in AWS with awspec

Spin up an AWS EC2 instance When a new instance has been loaded test the command line config

``aws ec2 describe-instances``

See: http://docs.aws.amazon.com/cli/latest/userguide/shorthand-syntax.html

Page 16: Validating Puppet managed resources in AWS with awspec

Install some Ruby dependencies Install RVM to make it easier to use different versions of Ruby

See: https://rvm.io/rvm/install

Page 17: Validating Puppet managed resources in AWS with awspec

Follow the awspec README.md guide

The instructions explain what you need to do to write your tests

See: https://github.com/k1LoW/awspec

Page 18: Validating Puppet managed resources in AWS with awspec

Try auto-generating a test The instructions explain what you need to do to write your tests

See: https://github.com/k1LoW/awspec

Page 19: Validating Puppet managed resources in AWS with awspec

The result of auto-generation

Base Dockerfile installing the Will project

Page 20: Validating Puppet managed resources in AWS with awspec

There is a minor adjustment required

Base Dockerfile installing the Will project

Need to include a line at the top of the file to include the helper script.

Page 21: Validating Puppet managed resources in AWS with awspec

Add the helper script if necessary

This is required for the awspec methods to work correctly.

Page 22: Validating Puppet managed resources in AWS with awspec

Run your example test

Run your test suite. Note: in this case I wanted to see the exit code.

Page 23: Validating Puppet managed resources in AWS with awspec

Run your example test

You should see your tests passing. If not, you’ll need to debug.

Page 24: Validating Puppet managed resources in AWS with awspec

So what should we test?

Great question! That was a simple example to get you started.

Take time to understand what expectations you can define.

Here is a good question to get you in a testing mindset….

What would make you sleep better than knowing that configuration has been correctly applied?

Page 25: Validating Puppet managed resources in AWS with awspec

Enjoy and share what you do….

I’m on Twitter: @dkcwdLinkedIn: https://au.linkedin.com/in/daveclarkprofile