![Page 1: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/1.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/2.jpg)
First a little background….
![Page 3: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/5.jpg)
Why test our resources?
?
![Page 6: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/11.jpg)
Ok, so let’s talk about awspec….
![Page 12: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/12.jpg)
Make sure you find the right library
https://github.com/k1LoW/awspec
![Page 13: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/13.jpg)
Based on Serverspechttps://github.com/k1LoW/awspec
![Page 14: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/19.jpg)
The result of auto-generation
Base Dockerfile installing the Will project
![Page 20: Validating Puppet managed resources in AWS with awspec](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/20.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/21.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/22.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/23.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/24.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062523/5872e7f91a28abfa548b65bf/html5/thumbnails/25.jpg)
Enjoy and share what you do….
I’m on Twitter: @dkcwdLinkedIn: https://au.linkedin.com/in/daveclarkprofile