Skip to content

Instantly share code, notes, and snippets.

@rssnyder
Last active March 5, 2024 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rssnyder/778471492d5e511a4c0cfa5192df2522 to your computer and use it in GitHub Desktop.
Save rssnyder/778471492d5e511a4c0cfa5192df2522 to your computer and use it in GitHub Desktop.
creating member account connectors with terraform
Linked account name Linked account Type
000000000001 aws-account-one Linked Account
000000000002 aws-account-two Linked Account
000000000003 aws-account-three Linked Account
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"
}
}
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