This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract a usage pattern for IAM instance profile. The instance level should setup this module and pass the role name to modules that attach the policy. Refer to single-node-asg and persistent-ebs for usage. Simply export profile id for attaching to instance, and role name for ataching policies.
- Loading branch information
Showing
11 changed files
with
98 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# IAM Instance Profile | ||
|
||
This module abstracts the useage pattern of IAM instance profile. The caller provides role/policy, and gets profile id to assign to instance. | ||
|
||
Sample usgae: | ||
|
||
``` | ||
module "iam_instance_profile" { | ||
source = "../iam-instance-profile" | ||
assume_role_policy = "${data.aws_iam_policy_document.attach_ebs.json}" | ||
policy = "${data.aws_iam_policy_document.attach_ebs_policy.json}" | ||
name_prefix = "persistent-ebs" | ||
} | ||
module "server" { | ||
source = "../asg" | ||
iam_profile = "${module.iam_instance_profile.iam_profile_id}" | ||
# other things here is ignored | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
variable "name_prefix" { | ||
description = "Creates a unique name beginning with the specified prefix." | ||
} | ||
|
||
resource "aws_iam_instance_profile" "profile" { | ||
name_prefix = var.name_prefix | ||
role = aws_iam_role.role.name | ||
} | ||
|
||
resource "aws_iam_role" "role" { | ||
name = var.name_prefix | ||
path = "/" | ||
assume_role_policy = <<-EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "ec2.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
} | ||
|
||
output "iam_role_name" { | ||
value = aws_iam_role.role.name | ||
} | ||
|
||
output "iam_profile_id" { | ||
value = aws_iam_instance_profile.profile.id | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters