diff --git a/README.md b/README.md index 1048a71..0eac6d6 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ In it's most minimal input, this module will create an S3 bucket to store the ge ```hcl module "aws-energy-labeler" { - source = "schubergphilis/mcaf-energy-labeler/aws" + source = "schubergphilis/mcaf-energy-labeler/aws" kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" @@ -18,16 +18,30 @@ module "aws-energy-labeler" { } ``` +Or to target a single account: + +```hcl +module "aws-energy-labeler" { + source = "schubergphilis/mcaf-energy-labeler/aws" + + kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" + + config = { + single_account_id = "123456789012" + } +} +``` + Should you prefer to use an existing bucket, you can specify the bucket name: ```hcl module "aws-energy-labeler" { - source = "schubergphilis/mcaf-energy-labeler/aws" + source = "schubergphilis/mcaf-energy-labeler/aws" kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" config = { - zone_name = "MYZONE" + zone_name = "MYZONE" } bucket_name = "mybucket" @@ -44,7 +58,7 @@ module "aws-energy-labeler" { "otherzone" = { allowed_account_ids = ["234567890123"] }, } - source = "schubergphilis/mcaf-energy-labeler/aws" + source = "schubergphilis/mcaf-energy-labeler/aws" name = "aws-energy-labeler-${each.value}" kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" diff --git a/examples/basic/main.tf b/examples/basic/main.tf index d62d0d9..c1077ae 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -9,11 +9,19 @@ terraform { } } -provider "aws" { - region = "eu-west-1" +provider "aws" {} + +module "aws-energy-labeler-single-account" { + source = "../../" + + kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" + + config = { + single_account_id = "123456789012" + } } -module "aws-energy-labeler" { +module "aws-energy-labeler-zone" { source = "../../" kms_key_arn = "arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-123456789012" diff --git a/main.tf b/main.tf index 6ab1bab..b6eed78 100644 --- a/main.tf +++ b/main.tf @@ -18,6 +18,7 @@ locals { frameworks = length(var.config.frameworks) > 0 ? join(", ", var.config.frameworks) : null organizations_zone_name = var.config.zone_name region = data.aws_region.current.name + single_account_id = var.config.single_account_id } ) diff --git a/variables.tf b/variables.tf index fd75d15..5cf24ef 100644 --- a/variables.tf +++ b/variables.tf @@ -39,9 +39,15 @@ variable "config" { frameworks = optional(list(string), []) log_level = optional(string) report_suppressed_findings = optional(bool, false) - zone_name = string + single_account_id = optional(string) + zone_name = optional(string) }) description = "Map containing labeler configuration options" + + validation { + condition = var.config.zone_name != "" || var.config.single_account_id != "" + error_message = "Either zone_name or single_account_id is required" + } } variable "kms_key_arn" {