I'm looking for a way to list out existing IAM roles in a Cloudformation Template in a similar way to listing say EC2 Key Pairs. Below is an example of what I'm trying with both EC2 Key Pairs and IAM Roles however Cloudformation throws an error saying that "RoleName" does not exist.
"KeyName": {
"Description" : "Choose a Key Pair that is available in this region",
"Type": "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription": "Must be the name of an existing EC2 Key Pair"
},
"ServiceRole": {
"Description" : "Choose an IAM Role that is available in this region",
"Type": "AWS::IAM::Role::RoleName",
"ConstraintDescription": "Must be the name of an existing IAM Role"
},
Screenshot of Cloudformation Interface Any ideas if this is possible to achieve?
You can pass multiple values for individual parameters in an AWS CloudFormation template using one of these ways: Use AWS-specific parameter types to select values from a prepopulated list of existing AWS values from an AWS account. Use CommaDelimitedList parameter types to specify your own values.
To add an existing or new IAM managed policy to a new IAM role resource, use the ManagedPolicyArns property of resource type AWS::IAM::Role. To add a new IAM managed policy to an existing IAM role resource, use the Roles property of resource type AWS::IAM::ManagedPolicy.
AWS CloudFormation templates can contain parameters. Parameters can be used inside the CloudFormation template to refer to values that are provided at the time the CloudFormation template is used to create a new stack.
Parameters (optional) Values to pass to your template at runtime (when you create or update a stack). You can refer to parameters from the Resources and Outputs sections of the template.
Not all types are supported in dropdown lists, and IAM Roles are not a supported type. So you cannot get a dropdown for IAM roles. Instead, you will have to use a simple text box.
Here is the current list of supported parameter types:
String
Number
List<Number>
CommaDelimitedList
AWS::EC2::AvailabilityZone::Name
AWS::EC2::Image::Id
AWS::EC2::Instance::Id
AWS::EC2::KeyPair::KeyName
AWS::EC2::SecurityGroup::GroupName
AWS::EC2::SecurityGroup::Id
AWS::EC2::Subnet::Id
AWS::EC2::Volume::Id
AWS::EC2::VPC::Id
AWS::Route53::HostedZone::Id
List<AWS::EC2::AvailabilityZone::Name>
List<AWS::EC2::Image::Id>
List<AWS::EC2::Instance::Id>
List<AWS::EC2::SecurityGroup::GroupName>
List<AWS::EC2::SecurityGroup::Id>
List<AWS::EC2::Subnet::Id>
List<AWS::EC2::Volume::Id>
List<AWS::EC2::VPC::Id>
List<AWS::Route53::HostedZone::Id>
Source: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With