AWS IAM User Policy Attachment
This page shows how to write Terraform and CloudFormation for IAM User Policy Attachment and write them securely.
aws_iam_user_policy_attachment (Terraform)
The User Policy Attachment in IAM can be configured in Terraform with the resource name aws_iam_user_policy_attachment
. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_iam_user_policy_attachment" "github_ci_dynamodb" {
user = aws_iam_user.github_actions_ci.name
policy_arn = data.aws_iam_policy.dynamodb_full_access.arn
}
resource "aws_iam_user_policy_attachment" "github_ci_s3" {
resource "aws_iam_user_policy_attachment" "iam-full-access" {
provider = aws.iam
policy_arn = data.aws_iam_policy.IAMFullAccess.arn
user = aws_iam_user.iam-manager.name
}
Parameters
-
id
optional computed - string -
policy_arn
required - string -
user
required - string
Explanation in Terraform Registry
Attaches a Managed IAM Policy to an IAM user
NOTE: The usage of this resource conflicts with the
aws_iam_policy_attachment
resource and will permanently show a difference if both are defined.
Tips: Best Practices for The Other AWS IAM Resources
In addition to the aws_iam_account_password_policy, AWS IAM has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_iam_account_password_policy
Ensure AWS IAM account password policies requires long passwords
It's better to enforce the use of long and complex passwords to reduce the risk of bruteforce attacks.
AWS::IAM::User (CloudFormation)
The User in IAM can be configured in CloudFormation with the resource name AWS::IAM::User
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: "AWS::IAM::User"
Properties:
Groups:
- Devusers
- Produsers
- PrimeUsers
Type: "AWS::IAM::User"
Properties:
Groups:
- DevUsers
- ProdUsers
- PrimeUsers
Type: "AWS::IAM::User"
Properties:
Groups:
- DevUsers
- ProdUsers
- PrimeUsers
Type: "AWS::IAM::User"
Properties:
Groups:
- Devusers
- Produsers
- PrimeUsers
Type: "AWS::IAM::User"
Properties:
Groups:
- DevUsers
- ProdUsers
- PrimeUsers
"Type" : "AWS::IAM::User",
"Properties" : {
"UserName" : "applicationadministrator",
"Path" : "/",
"Groups" : [
{ "Fn::ImportValue" : { "Fn::Sub" : "${CustomGroupsStackName}-ApplicationAdministratorsGroup" }}
"Type" : "AWS::IAM::User",
"Properties" : {
"UserName" : "applicationadministrator",
"Path" : "/",
"Groups" : [
{ "Fn::ImportValue" : { "Fn::Sub" : "${CustomGroupsStackName}-ApplicationAdministratorsGroup" }}
"Type": "AWS::IAM::User",
"Properties": {
"UserName": "Scout2User001",
"Groups": [
"BlockedUsers"
]
"Type": "AWS::IAM::User",
"Properties": {
"UserName": "TestUser1",
"Path": "/"
}
},
"Type" : "AWS::IAM::User",
"Properties" : {
"UserName" : "mcrawford",
"Path" : "/",
"Groups" : [{ "Fn::ImportValue" : { "Fn::Sub" : "${StandardGroupsStackName}-AdministratorsGroup" }}]
}
Parameters
-
Groups
optional - List -
LoginProfile
optional - LoginProfile -
ManagedPolicyArns
optional - List -
Path
optional - String -
PermissionsBoundary
optional - String -
Policies
optional - List of Policy -
Tags
optional - List of Tag -
UserName
optional - String
Explanation in CloudFormation Registry
Creates a new IAM user for your AWS account. For information about quotas for the number of IAM users you can create, see IAM and AWS STS quotas in the IAM User Guide.
Frequently asked questions
What is AWS IAM User Policy Attachment?
AWS IAM User Policy Attachment is a resource for IAM of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS IAM User Policy Attachment?
For Terraform, the jasongwartz/fitbit-friends and stilist/drjohndee.net source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the ServerlessOpsIO/infrastructure, ServerlessOpsIO/infrastructure and ServerlessOpsIO/infrastructure source code examples are useful. See the CloudFormation Example section for further details.