From dab4bf49130c8c55bd2e0219707514c08a7fd1a4 Mon Sep 17 00:00:00 2001 From: Sebastian Melchior Date: Tue, 20 Feb 2018 11:21:09 +0100 Subject: [PATCH 1/3] add tag option --- cloudtrail.tf | 1 + s3_cloudtrail.tf | 4 +++- variables.tf | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cloudtrail.tf b/cloudtrail.tf index 0d4180f..fd5ecc2 100644 --- a/cloudtrail.tf +++ b/cloudtrail.tf @@ -5,4 +5,5 @@ resource "aws_cloudtrail" "global_Default" { is_multi_region_trail = true include_global_service_events = true enable_log_file_validation = true + tags = "${merge(var.tags, map("Name", format("%s", var.trail_name)))}" } diff --git a/s3_cloudtrail.tf b/s3_cloudtrail.tf index bc564e6..46cecac 100644 --- a/s3_cloudtrail.tf +++ b/s3_cloudtrail.tf @@ -2,7 +2,7 @@ resource "aws_s3_bucket" "cloudtrail_bucket" { bucket = "${local.bucket_name}" acl = "private" count = "${var.trail_bucketname_create}" - + server_side_encryption_configuration { rule { apply_server_side_encryption_by_default { @@ -11,6 +11,8 @@ resource "aws_s3_bucket" "cloudtrail_bucket" { } } } + + tags = "${merge(var.tags, map("Name", format("%s", local.bucket_name)))}" } resource "aws_s3_bucket_policy" "cloudtrail_bucket_policy" { diff --git a/variables.tf b/variables.tf index 53d1216..df8a4e8 100644 --- a/variables.tf +++ b/variables.tf @@ -53,4 +53,9 @@ variable "trail_bucket_default_encryption" { variable "trail_bucket_default_encryption_key" { description = "Defines if the KMS encryption key, used if trail_bucket_default_encryption is set to aws:kms" default = "" -} \ No newline at end of file +} + +variable "tags" { + description = "A map of tags to add to all resources" + default = {} +} From 8509e4c7a95eb410c47e778703db39d5653355c7 Mon Sep 17 00:00:00 2001 From: Sebastian Melchior Date: Wed, 28 Feb 2018 09:32:43 +0100 Subject: [PATCH 2/3] add name_tag_name, add type for tags var --- s3_cloudtrail.tf | 2 +- variables.tf | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/s3_cloudtrail.tf b/s3_cloudtrail.tf index 46cecac..ecc9915 100644 --- a/s3_cloudtrail.tf +++ b/s3_cloudtrail.tf @@ -12,7 +12,7 @@ resource "aws_s3_bucket" "cloudtrail_bucket" { } } - tags = "${merge(var.tags, map("Name", format("%s", local.bucket_name)))}" + tags = "${merge(var.tags, map(var.name_tag_name, format("%s", local.bucket_name)))}" } resource "aws_s3_bucket_policy" "cloudtrail_bucket_policy" { diff --git a/variables.tf b/variables.tf index df8a4e8..f6f9b16 100644 --- a/variables.tf +++ b/variables.tf @@ -58,4 +58,10 @@ variable "trail_bucket_default_encryption_key" { variable "tags" { description = "A map of tags to add to all resources" default = {} + type = "map" +} + +variable "name_tag_name" { + description = "Name of the 'name' tag that is added to, for example, the S3 resources" + default = "Name" } From 9b21b62dc430be085b98d5ae683835d32f959d40 Mon Sep 17 00:00:00 2001 From: Sebastian Melchior Date: Wed, 28 Feb 2018 10:07:03 +0100 Subject: [PATCH 3/3] change another name tag --- cloudtrail.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudtrail.tf b/cloudtrail.tf index fd5ecc2..1e03e03 100644 --- a/cloudtrail.tf +++ b/cloudtrail.tf @@ -5,5 +5,5 @@ resource "aws_cloudtrail" "global_Default" { is_multi_region_trail = true include_global_service_events = true enable_log_file_validation = true - tags = "${merge(var.tags, map("Name", format("%s", var.trail_name)))}" + tags = "${merge(var.tags, map(var.name_tag_name, format("%s", var.trail_name)))}" }