The Complete CloudFormation Guide: Parameters and Refs
Table of Contents
- Introduction
- What Are We Doing?
- The Video: Parameters & Refs
- The Template So Far
- Next Steps
- The Complete CloudFormation Guide Index
Introduction
So right now our template is reusable but not as much as it could be since we have some stuff hard-coded into it (like the author name and the SSH range). Since we would prefer that to not be the case, we're going to discuss the solutions available to us here with Parameters and Refs. Parameters are how we can pass our template custom settings on creation so that the stack we've created with it won't be limited to the things that are hard-coded into it. And Refs, aka references, are what allows us to use parameters throughout our template and they're also how we can have resources reference one another.
To see how these two properties work in practice, we'll be returning to our template with an eye on making it more reusable in the future. Something to keep in mind: Refs are special functions in CloudFormation, named intrinsic functions. Intrinsic functions are something we'll discuss multiple times in this series and they're all used in similar ways so we'll look into some other options available to us with them.
Now, parameters are one of those things that make a LOT more sense once you see them in action so be sure to experiment with them on your own to see how useful they can be. In the end, our security group and template are at a state where we can actually launch it, so that's what we'll be onto doing next!
What Are We Doing?
In this video, we'll be returning to our AWS CloudFormation template to set up a couple of Parameters which will make our template more flexible when being reused. We'll also discuss AWS-specific and SSM parameter types. Then, using the Parameters section in the console, we'll practice how to use refs to bind parts of our template to one another.
The Video: Parameters & Refs
The Template So Far
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description": "A CFN template for learning",
"Metadata": {
"Author": { "Ref": "ParamAuthorName" }
},
"Parameters": {
"ParamAuthorName": {
"Type": "String",
"Description": "Owner of the CFN Template."
},
"ParamAllowSSHFromRange": {
"Type": "String",
"Description": "IP CidrBlock to allow SSH access. i.e. 100.100.100.100/32",
"Default": "0.0.0.0/0"
}
},
"Resources": {
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupName": "instance-sg",
"GroupDescription": "Security group for SSH and HTTP access",
"SecurityGroupIngress": [
{
"IpProtocol":"tcp",
"FromPort":"80",
"ToPort":"80",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol":"tcp",
"FromPort":"22",
"ToPort":"22",
"CidrIp": { "Ref": "ParamAllowSSHFromRange" }
}
]
}
}
}
}
Next Steps
The Next Post - Our First Time Launch
The Previous Post - Resources
The Complete CloudFormation Guide Index
If you're enjoying this series and finding it useful, be sure to check out the rest of the blog posts in it! The links below will take you to the other posts in The Complete CloudFormation Guide here on Tech Guides and Thoughts so you can continue building your CloudFormation template along with me.
- The Complete CloudFormation Guide
- An Introduction to and History of CloudFormation
- The Main Concepts of CloudFormation
- How CloudFormation Does Updates and Deletes
- Our Project Setup
- Resources
- Parameters and Refs
- Our First Time Launch
- Functions, Pseudo Parameters, and Conditions Part 1
- Functions, Pseudo Parameters, and Conditions Part 2
- Mappings
- Transforms
- Outputs
- Relaunch!
- The Best Next Steps to Take from Here
Enjoy Posts Like These? Sign up to my mailing list!
J Cole Morrison
http://start.jcolemorrison.comDeveloper Advocate @HashiCorp, DevOps Enthusiast, Startup Lover, Teaching at awsdevops.io