generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditionally enable SSM Default Host Management Configuration (#71)
* By default, AWS Systems Manager doesn't have permission to perform actions on your instances. * Default Host Management Configuration allows Systems Manager to manage your Amazon EC2 instances automatically. * After you've turned on this setting, all instances using Instance Metadata Service Version 2 (IMDSv2) in the AWS Region and AWS account with SSM Agent version 3.2.582.0 or later installed automatically become managed instances. Benefits of managed instances include the following: * Connect to your instances securely using Session Manager. * Perform automated patch scans using Patch Manager. * View detailed information about your instances using Systems Manager Inventory. * Track and manage instances using Fleet Manager. * Keep the SSM Agent up to date automatically.
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 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,13 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": ${services} | ||
}, | ||
"Action": "sts:AssumeRole" | ||
} | ||
] | ||
} |
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,46 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ssm:DescribeAssociation", | ||
"ssm:GetDeployablePatchSnapshotForInstance", | ||
"ssm:GetDocument", | ||
"ssm:DescribeDocument", | ||
"ssm:GetManifest", | ||
"ssm:ListAssociations", | ||
"ssm:ListInstanceAssociations", | ||
"ssm:PutInventory", | ||
"ssm:PutComplianceItems", | ||
"ssm:PutConfigurePackageResult", | ||
"ssm:UpdateAssociationStatus", | ||
"ssm:UpdateInstanceAssociationStatus", | ||
"ssm:UpdateInstanceInformation" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ssmmessages:CreateControlChannel", | ||
"ssmmessages:CreateDataChannel", | ||
"ssmmessages:OpenControlChannel", | ||
"ssmmessages:OpenDataChannel" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2messages:AcknowledgeMessage", | ||
"ec2messages:DeleteMessage", | ||
"ec2messages:FailMessage", | ||
"ec2messages:GetEndpoint", | ||
"ec2messages:GetMessages", | ||
"ec2messages:SendReply" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} |
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,30 @@ | ||
resource "aws_iam_role" "ssm_dhmc" { | ||
count = local.enable_ssm_dhmc ? 1 : 0 | ||
|
||
name = "${local.project_name}-ssm-dhmc" | ||
assume_role_policy = templatefile( | ||
"${path.root}/policies/assume-roles/service-principle-standard.json.tpl", | ||
{ services = jsonencode(["ssm.amazonaws.com"]) } | ||
) | ||
} | ||
|
||
resource "aws_iam_policy" "ssm_dhmc" { | ||
count = local.enable_ssm_dhmc ? 1 : 0 | ||
|
||
name = "${local.project_name}-ssm-dhmc" | ||
policy = templatefile("${path.root}/policies/ssm-dhmc.json.tpl", {}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "ssm_dhmc" { | ||
count = local.enable_ssm_dhmc ? 1 : 0 | ||
|
||
role = aws_iam_role.ssm_dhmc[0].name | ||
policy_arn = aws_iam_policy.ssm_dhmc[0].arn | ||
} | ||
|
||
resource "aws_ssm_service_setting" "ssm_dhmc" { | ||
count = local.enable_ssm_dhmc ? 1 : 0 | ||
|
||
setting_id = "arn:aws:ssm:${local.aws_region}:${local.aws_account_id}:servicesetting/ssm/managed-instance/default-ec2-instance-management-role" | ||
setting_value = aws_iam_role.ssm_dhmc[0].name | ||
} |
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