Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit c8ad722

Browse files
committed
Delegate account ID fetching to the implementation
This enables the module to be a little bit more flexible about which accounts are set up for CloudTrail. Also added CHANGELOG.md
1 parent d9d274d commit c8ad722

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [1.0.0] - 2019-01-13
8+
### Changed
9+
- Remove functionality for getting account IDs in module, delegated to implementation
10+
11+
## [0.1.0] - 2019-01-13
12+
- Initial release

cloudtrail.tf

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ data "aws_caller_identity" "master" {
2424
provider = aws.master
2525
}
2626

27-
data "terraform_remote_state" "globals" {
28-
backend = "s3"
29-
workspace = "global"
30-
config = {
31-
bucket = "${var.global_state_bucket}"
32-
key = "${var.global_state_key}"
33-
region = "${var.global_state_region}"
34-
profile = "${var.global_state_profile}"
35-
}
36-
}
37-
3827
resource "aws_kms_alias" "cloudtrail" {
3928
provider = aws.master
4029

@@ -105,7 +94,7 @@ resource "aws_kms_key" "cloudtrail" {
10594
"Action": "kms:GenerateDataKey*",
10695
"Condition": {
10796
"ForAllValues:StringLike": {
108-
"kms:EncryptionContext:aws:cloudtrail:arn": ${jsonencode([for id in data.terraform_remote_state.globals.outputs.aws_account_ids : join("", ["arn:aws:cloudtrail:*:", id, ":trail/*"])])}
97+
"kms:EncryptionContext:aws:cloudtrail:arn": ${jsonencode([for id in var.account_ids : join("", ["arn:aws:cloudtrail:*:", id, ":trail/*"])])}
10998
}
11099
},
111100
"Effect": "Allow",
@@ -121,7 +110,7 @@ resource "aws_kms_key" "cloudtrail" {
121110
"Effect": "Allow",
122111
"Principal": {
123112
"AWS": [
124-
"arn:aws:iam::${data.terraform_remote_state.globals.outputs.aws_account_ids.master}:root"
113+
"arn:aws:iam::${data.aws_caller_identity.master.account_id}:root"
125114
]
126115
},
127116
"Action": [
@@ -138,7 +127,7 @@ resource "aws_kms_key" "cloudtrail" {
138127
"Effect": "Allow",
139128
"Principal": {
140129
"AWS": [
141-
"arn:aws:iam::${data.terraform_remote_state.globals.outputs.aws_account_ids.master}:root"
130+
"arn:aws:iam::${data.aws_caller_identity.master.account_id}:root"
142131
]
143132
},
144133
"Action": [
@@ -165,14 +154,14 @@ resource "aws_kms_key" "s3" {
165154
resource "aws_kms_alias" "s3" {
166155
provider = aws.master
167156

168-
name = "alias/s3"
157+
name = "alias/s3"
169158
target_key_id = "${aws_kms_key.s3.key_id}"
170159
}
171160

172161
resource "aws_s3_bucket" "main" {
173162
provider = aws.audit
174163

175-
bucket = "s3-${var.client_name}-cloudtrail"
164+
bucket = "s3-${var.client_name}-cloudtrail"
176165
force_destroy = true
177166
versioning {
178167
enabled = true
@@ -181,7 +170,7 @@ resource "aws_s3_bucket" "main" {
181170
rule {
182171
apply_server_side_encryption_by_default {
183172
kms_master_key_id = "${aws_kms_alias.s3.arn}"
184-
sse_algorithm = "aws:kms"
173+
sse_algorithm = "aws:kms"
185174
}
186175
}
187176
}

outputs.tf

Lines changed: 0 additions & 1 deletion
This file was deleted.

variables.tf

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@ variable "client_name" {
22
description = "Name of the organisation, used in the bucket name to ensure there are no conflicts"
33
}
44

5-
variable "global_state_bucket" {
6-
description = "The name of the bucket containing the global module state"
7-
}
8-
9-
variable "global_state_key" {
10-
description = "The key of the global module state as defined in the backend"
11-
}
12-
13-
variable "global_state_region" {
14-
description = "The region of the bucket containing the global module state"
15-
}
16-
17-
variable "global_state_profile" {
18-
description = "The profile to be used to access the global module state bucket"
5+
variable "account_ids" {
6+
description = "A list of account IDs permitted to send trails to the org master"
7+
type = list(string)
198
}

0 commit comments

Comments
 (0)