Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create IAM Role Dropdown in Cloudformation Template Parameters

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?

like image 885
Adam Synnott Avatar asked Aug 12 '17 14:08

Adam Synnott


People also ask

How do you pass parameters in CloudFormation?

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.

How can we create IAM role in CloudFormation?

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.

What does the parameters section in an AWS CloudFormation template do?

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.

What part of a CloudFormation template allows you to pass values into the template?

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.


1 Answers

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

like image 71
Matt Houser Avatar answered Oct 25 '22 08:10

Matt Houser