Skip to content

Commit

Permalink
feat: Add config option for single account ID
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Hoekstra <[email protected]>
  • Loading branch information
mikef-nl authored and shoekstra committed Dec 9, 2024
1 parent eedb2f2 commit bbe8be5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
14 changes: 11 additions & 3 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit bbe8be5

Please sign in to comment.