Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of CloudWatch logging, additional policy attachment, and KMS decryption #111

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
da5777a
updated module to also instance ec2 instance connect
cc-robertson Mar 22, 2021
b8afd84
updated vars, provider inputs & configuration for host_name records i…
cc-robertson Mar 22, 2021
507924c
feat: added cloudwatch log group to bastion module
cc-robertson Feb 2, 2022
3a470b1
resolved merge conflict
cc-robertson Feb 2, 2022
e284f6f
Merge branch 'cloudposse-master'
cc-robertson Feb 2, 2022
7de4989
feat: removed unneccessary varaibles that get loaded by terragrunt fr…
cc-robertson Feb 2, 2022
d14aabc
Merge branch 'master' into HT-4046
cc-robertson Feb 2, 2022
9b5bff1
fix: resolved outputs from cloudwatch
cc-robertson Feb 2, 2022
716f73e
fix: resolved outputs from cloudwatch
cc-robertson Feb 2, 2022
43f9cc2
fix: resolved outputs from cloudwatch
cc-robertson Feb 2, 2022
6124809
feat: removed isntance connect
cc-robertson Feb 4, 2022
71f4605
fix: removed conenct logic from user_data
cc-robertson Feb 4, 2022
58f9537
Merge pull request #1 from humn-ai/HT-4046
Callumccr Feb 4, 2022
018638d
feat: updated user_data, updated IAM policy for instance profile
cc-robertson Feb 8, 2022
3f83262
added kms:generatedatakey"
cc-robertson Feb 8, 2022
bd41d31
added additional iam policy
cc-robertson Feb 8, 2022
505dd40
added kms:generatedatakey"
cc-robertson Feb 8, 2022
abe649d
fixed existing policies
cc-robertson Feb 8, 2022
2c4f560
fixed existing policies
cc-robertson Feb 8, 2022
8a16910
fixed existing policies
cc-robertson Feb 8, 2022
bb7a7f2
fixed existing policies
cc-robertson Feb 8, 2022
b262af7
feat: added tags to ebs volume
cc-robertson Feb 14, 2022
236ad73
Merge 'cloudposse/master' -v0.30.1
Jul 21, 2022
0c51188
Merge pull request #5 from humn-ai/HT-7895-update-latest
yadachi Jul 21, 2022
c372b2c
fix: add versions.tf and remove terraform.tf
Jul 22, 2022
34b643d
fix: pass kms_key_arn in the policy
Jul 22, 2022
8904c3e
Merge pull request #6 from humn-ai/HT-7895-fix-policy
yadachi Jul 22, 2022
9fbae47
feat(tf): Update config to be suitable for a CloudPosse PR
LawrenceWarren Sep 6, 2023
ee13915
fix(tf): Restore amazon-linux.sh script
LawrenceWarren Sep 6, 2023
92eb54b
Merge branch 'main' into cloudposse-pr-branch
LawrenceWarren Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "cloudwatch_logs" {
count = module.this.enabled && var.cloudwatch_logs_enabled == true ? 1 : 0
source = "cloudposse/cloudwatch-logs/aws"
version = "0.6.4"
context = module.this.context
attributes = ["log-group"]
kms_key_arn = var.kms_key_arn != "" ? var.kms_key_arn : null
retention_in_days = var.retention_in_days
}
27 changes: 27 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ resource "aws_iam_role" "default" {
assume_role_policy = data.aws_iam_policy_document.default.json
}

resource "aws_iam_role_policy_attachment" "existing_policies" {
count = module.this.enabled && length(var.existing_policy_arns) > 0 ? length(var.existing_policy_arns) : 0
role = aws_iam_role.default[0].name
policy_arn = var.existing_policy_arns[count.index]
}


resource "aws_iam_role_policy" "main" {
count = module.this.enabled && local.create_instance_profile ? 1 : 0
name = module.this.id
Expand Down Expand Up @@ -100,4 +107,24 @@ data "aws_iam_policy_document" "main" {

resources = ["*"]
}

statement {
effect = "Allow"

actions = [
"kms:Decrypt"
]

resources = [var.kms_key_arn]
}

statement {
effect = "Allow"

actions = [
"kms:GenerateDataKey"
]

resources = ["*"]
}
}
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ resource "aws_instance" "default" {
volume_size = var.ebs_block_device_volume_size
delete_on_termination = var.ebs_delete_on_termination
device_name = var.ebs_device_name
tags = module.this.tags
}
}

Expand Down
5 changes: 5 additions & 0 deletions user_data/amazon-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ then
systemctl enable amazon-ssm-agent
systemctl start amazon-ssm-agent
systemctl status amazon-ssm-agent

sudo mkdir -p /etc/amazon/ssm
sudo cp -pr /snap/amazon-ssm-agent/current/* /etc/amazon/ssm
sudo cp -p /etc/amazon/ssm/seelog.xml.template /etc/amazon/ssm/seelog.xml

else
systemctl disable amazon-ssm-agent
systemctl stop amazon-ssm-agent
Expand Down
30 changes: 28 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ variable "security_group_rules" {
}
]
description = <<-EOT
A list of maps of Security Group rules.
The values of map is fully complated with `aws_security_group_rule` resource.
A list of maps of Security Group rules.
The values of map is fully complated with `aws_security_group_rule` resource.
To get more info see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule .
EOT
}
Expand Down Expand Up @@ -217,3 +217,29 @@ variable "instance_profile" {
description = "A pre-defined profile to attach to the instance (default is to build our own)"
default = ""
}

variable "existing_policy_arns" {
description = "(Optional) - A list of existing policy ARNs to associate with the role"
type = list(string)
default = []
}

variable "cloudwatch_logs_enabled" {
type = bool
default = false
description = "(Optional) - Flag to enable session logs to ship to a CloudWatch log group"
}

variable "kms_key_arn" {
description = <<-EOT
(Optional) - The ARN of the KMS Key to use when encrypting log data.
Please note, after the AWS KMS CMK is disassociated from the log group, AWS CloudWatch Logs stops encrypting newly ingested data for the log group.
All previously ingested data remains encrypted, and AWS CloudWatch Logs requires permissions for the CMK whenever the encrypted data is requested.
EOT
default = ""
}

variable "retention_in_days" {
description = "(Optional) - Number of days you want to retain log events in the log group"
default = "30"
}
Loading