Last active
March 5, 2024 20:03
-
-
Save rssnyder/778471492d5e511a4c0cfa5192df2522 to your computer and use it in GitHub Desktop.
creating member account connectors with terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Linked account name | Linked account | Type | |
---|---|---|---|
000000000001 | aws-account-one | Linked Account | |
000000000002 | aws-account-two | Linked Account | |
000000000003 | aws-account-three | Linked Account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
harness = { | |
source = "harness/harness" | |
} | |
} | |
} | |
# CSV Example | |
locals { | |
# pull in accounts csv | |
accounts_raw = csvdecode(file("./accounts.csv")) | |
# only get linked account (ignore masters) | |
accounts = [for account in local.accounts_raw : account if account["Type"] == "Linked Account"] | |
} | |
resource "harness_platform_connector_awscc" "csv" { | |
for_each = { for account in local.accounts : "${trimspace(account["Linked account name"])}" => account } | |
identifier = replace(trimspace(each.value["Linked account"]), "-", "_") | |
name = replace(trimspace(each.value["Linked account"]), "-", "_") | |
account_id = trimspace(each.value["Linked account name"]) | |
features_enabled = [ | |
"OPTIMIZATION", | |
"VISIBILITY", | |
"GOVERNANCE", | |
] | |
cross_account_access { | |
role_arn = "arn:aws:iam::${trimspace(each.value["Linked account name"])}:role/HarnessCERole" | |
external_id = "harness:891928451355:qwerty" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
harness = { | |
source = "harness/harness" | |
} | |
} | |
} | |
# AWS Data Source Example | |
data "aws_organizations_organization" "this" {} | |
resource "harness_platform_connector_awscc" "data" { | |
for_each = { for account in data.aws_organizations_organization.this.accounts : "${trimspace(account.name)}" => account } | |
identifier = replace(replace(trimspace(each.value.name), "-", "_"), " ", "_") | |
name = replace(replace(trimspace(each.value.name), "-", "_"), " ", "_") | |
account_id = trimspace(each.value.id) | |
features_enabled = [ | |
"OPTIMIZATION", | |
"VISIBILITY", | |
"GOVERNANCE", | |
] | |
cross_account_access { | |
role_arn = "arn:aws:iam::${trimspace(each.value.id)}:role/HarnessCERole" | |
external_id = "harness:891928451355:qwerty" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment