Skip to content

Commit 5687c3b

Browse files
feat: prefetch root org id (#59)
1 parent eb5fb6c commit 5687c3b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

modules/integrations/cloud-logs/main.tf

+14-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ data "sysdig_secure_cloud_ingestion_assets" "assets" {
4040
cloud_provider_id = data.aws_caller_identity.current.account_id
4141
}
4242

43+
#----------------------------------------------------------
44+
# Fetch & compute required data for organizational install
45+
#----------------------------------------------------------
46+
data "aws_organizations_organization" "org" {
47+
count = var.is_organizational ? 1 : 0
48+
}
49+
50+
4351
#-----------------------------------------------------------------------------------------
4452
# Generate a unique name for resources using random suffix and account ID hash
4553
#-----------------------------------------------------------------------------------------
@@ -69,6 +77,10 @@ locals {
6977

7078
# StackSet configuration
7179
stackset_name = "${var.name}-${random_id.suffix.hex}-${local.account_id_hash}-stackset"
80+
81+
# fetch the AWS Root OU under org
82+
# As per https://docs.aws.amazon.com/organizations/latest/userguide/orgs_getting-started_concepts.html#organization-structure, there can be only one root
83+
root_org_unit = var.is_organizational ? [for root in data.aws_organizations_organization.org[0].roots : root.id] : []
7284
}
7385

7486
#-----------------------------------------------------------------------------------------------------------------------
@@ -247,7 +259,7 @@ resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access_bucket" {
247259
stack_set_name = aws_cloudformation_stack_set.cloudlogs_s3_access[0].name
248260

249261
deployment_targets {
250-
organizational_unit_ids = var.org_units
262+
organizational_unit_ids = local.root_org_unit
251263
account_filter_type = "INTERSECTION"
252264
accounts = [local.bucket_account_id]
253265
}
@@ -268,7 +280,7 @@ resource "aws_cloudformation_stack_set_instance" "cloudlogs_s3_access_topic" {
268280
stack_set_name = aws_cloudformation_stack_set.cloudlogs_s3_access[0].name
269281

270282
deployment_targets {
271-
organizational_unit_ids = var.org_units
283+
organizational_unit_ids = local.root_org_unit
272284
account_filter_type = "INTERSECTION"
273285
accounts = [local.topic_account_id]
274286
}

modules/integrations/cloud-logs/variables.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ variable "sysdig_secure_account_id" {
33
description = "ID of the Sysdig Cloud Account to enable Cloud Logs integration for (in case of organization, ID of the Sysdig management account)"
44
}
55

6+
variable "is_organizational" {
7+
description = "(Optional) Set this field to 'true' to deploy CloudLogs to an AWS Organization (Or specific OUs)"
8+
type = bool
9+
default = false
10+
}
11+
612
variable "bucket_arn" {
713
description = "(Required) The ARN of your CloudTrail Bucket"
814
type = string
@@ -78,12 +84,6 @@ variable "timeout" {
7884
default = "30m"
7985
}
8086

81-
variable "org_units" {
82-
type = list(string)
83-
description = "List of AWS Organizations organizational unit (OU) IDs in which to create the StackSet instances. Required for cross-account organizational deployments."
84-
default = []
85-
}
86-
8787
variable "kms_key_arn" {
8888
description = "ARN of the KMS key used to encrypt the S3 bucket. If provided, the IAM role will be granted decrypt permissions."
8989
type = string

0 commit comments

Comments
 (0)