Skip to content

Commit

Permalink
feat: choose partition from context
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzieger committed Feb 19, 2024
1 parent 848c572 commit d247221
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
with:
terraform_version: 1.0.10

# note: we can only validate the example atm. see https://github.com/hashicorp/terraform/issues/28490
# note: we can only validate the example atm. see https://github.com/hashicorp/terraform/issues/28490
- run: terraform init -backend=false
working-directory: examples/basic-aws-integration

- run: terraform validate
working-directory: examples/basic-aws-integration

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Before opening a Pull Request, we recommend following the below steps to get a f
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.33.0 |
| <a name="provider_aws.automation"></a> [aws.automation](#provider\_aws.automation) | 5.33.0 |
| <a name="provider_aws.management"></a> [aws.management](#provider\_aws.management) | 5.33.0 |
| <a name="provider_aws.meshcloud"></a> [aws.meshcloud](#provider\_aws.meshcloud) | 5.33.0 |
Expand All @@ -186,6 +187,7 @@ Before opening a Pull Request, we recommend following the below steps to get a f
| [aws_caller_identity.automation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_caller_identity.management](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_caller_identity.meshcloud](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
## Inputs
Expand Down
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ data "aws_caller_identity" "automation" {
provider = aws.automation
}

data "aws_partition" "current" {}

module "meshcloud_account_metering_access" {
source = "./modules/meshcloud-cost-explorer/ce-meshcloud-account-access"
providers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data "aws_iam_policy_document" "cost_explorer_service_assume_role" {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
}
actions = ["sts:AssumeRole"]
condition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.21.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.7.0 |

## Modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data "aws_iam_policy_document" "meshcloud_cost_explorer_user_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::${var.management_account_id}:role/${var.management_account_service_role_name}"]
resources = ["arn:${data.aws_partition.current.partition}:iam::${var.management_account_id}:role/${var.management_account_service_role_name}"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data "aws_iam_policy_document" "meshfed_automation_assume_role" {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
}
actions = ["sts:AssumeRole"]
condition {
Expand Down Expand Up @@ -59,6 +59,6 @@ data "aws_iam_policy_document" "cloudformation_stackset_execution" {
sid = "VisualEditor0"
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole"]
resources = ["arn:${data.aws_partition.current.partition}:iam::*:role/AWSCloudFormationStackSetExecutionRole"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ No modules.
| [aws_iam_role_policy_attachment.meshfed_service_enrollment_additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.meshfed_service_enrollment_sc_adm_read](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.meshfed_service_enrollment_sc_enduser](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_servicecatalog_principal_portfolio_association.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/servicecatalog_principal_portfolio_association) | resource |
| [aws_servicecatalog_principal_portfolio_association.meshfed_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/servicecatalog_principal_portfolio_association) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.meshfed_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.meshfed_service_assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data "aws_iam_policy_document" "meshfed_service" {
sid = "StsAccessMemberAccount"
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::*:role/${var.meshstack_access_role_name}"]
resources = ["arn:${data.aws_partition.current.partition}:iam::*:role/${var.meshstack_access_role_name}"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
Expand All @@ -30,9 +30,9 @@ data "aws_iam_policy_document" "meshfed_service" {
"organizations:ListTagsForResource"
]
resources = [
"arn:aws:organizations::*:account/o-*/*",
"arn:aws:organizations::*:ou/o-*/ou-*",
"arn:aws:organizations::${local.account_id}:root/o-*/r-*"
"arn:${data.aws_partition.current.partition}:organizations::*:account/o-*/*",
"arn:${data.aws_partition.current.partition}:organizations::*:ou/o-*/ou-*",
"arn:${data.aws_partition.current.partition}:organizations::${local.account_id}:root/o-*/r-*"
]
}

Expand All @@ -49,9 +49,9 @@ data "aws_iam_policy_document" "meshfed_service" {
# The actions organizations:TagResource and organizations:UntagResource act on accounts.
# The actions can not be restricted to a subtree of the OU hierarchy. This is a limitation in the permission model of AWS Organization Service.
# To supprt tagging for this meshPlatform we need to allow both actions on all accounts.
"arn:aws:organizations::*:account/o-*/*",
"arn:${data.aws_partition.current.partition}:organizations::*:account/o-*/*",
# New accounts need to be moved from root to the target OU.
"arn:aws:organizations::${local.account_id}:root/o-*/r-*"
"arn:${data.aws_partition.current.partition}:organizations::${local.account_id}:root/o-*/r-*"
],
var.landing_zone_ou_arns)
}
Expand Down Expand Up @@ -80,8 +80,8 @@ data "aws_iam_policy_document" "meshfed_service" {
]
resources = [
"${var.aws_sso_instance_arn}",
"arn:aws:sso:::permissionSet/*/*",
"arn:aws:sso:::account/*"
"arn:${data.aws_partition.current.partition}:sso:::permissionSet/*/*",
"arn:${data.aws_partition.current.partition}:sso:::account/*"
]
}

Expand All @@ -99,8 +99,8 @@ data "aws_iam_policy_document" "meshfed_service" {
"iam:GetSAMLProvider"
]
resources = [
"arn:aws:iam::${local.account_id}:saml-provider/*",
"arn:aws:iam::${local.account_id}:role/*"
"arn:${data.aws_partition.current.partition}:iam::${local.account_id}:saml-provider/*",
"arn:${data.aws_partition.current.partition}:iam::${local.account_id}:role/*"
]
}
}
Expand All @@ -112,7 +112,7 @@ data "aws_iam_policy_document" "meshfed_service_assume_role" {
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
identifiers = ["arn:${data.aws_partition.current.partition}:iam::${var.meshcloud_account_id}:user/${var.meshcloud_account_service_user_name}"]
}
actions = ["sts:AssumeRole"]
condition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ resource "aws_iam_role_policy_attachment" "meshfed_service" {
resource "aws_iam_role_policy_attachment" "meshfed_service_enrollment_sc_enduser" {
count = var.control_tower_enrollment_enabled ? 1 : 0
role = aws_iam_role.meshfed_service.name
policy_arn = "arn:aws:iam::aws:policy/AWSServiceCatalogEndUserFullAccess"
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AWSServiceCatalogEndUserFullAccess"
}

resource "aws_iam_role_policy_attachment" "meshfed_service_enrollment_sc_adm_read" {
count = var.control_tower_enrollment_enabled ? 1 : 0
role = aws_iam_role.meshfed_service.name
policy_arn = "arn:aws:iam::aws:policy/AWSServiceCatalogAdminReadOnlyAccess"
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AWSServiceCatalogAdminReadOnlyAccess"
}

resource "aws_iam_policy" "meshfed_service_enrollment_additional" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.21.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.7.0 |

## Modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data "aws_iam_policy_document" "meshfed_service_user_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::${var.management_account_id}:role/${var.management_account_service_role_name}"]
resources = ["arn:${data.aws_partition.current.partition}:iam::${var.management_account_id}:role/${var.management_account_service_role_name}"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
Expand All @@ -20,7 +20,7 @@ data "aws_iam_policy_document" "meshfed_service_user_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = ["arn:aws:iam::${var.automation_account_id}:role/${var.automation_account_service_role_name}"]
resources = ["arn:${data.aws_partition.current.partition}:iam::${var.automation_account_id}:role/${var.automation_account_service_role_name}"]
condition {
test = "StringEquals"
variable = "sts:ExternalId"
Expand Down

0 comments on commit d247221

Please sign in to comment.