-
Notifications
You must be signed in to change notification settings - Fork 0
PLT-1224 #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
PLT-1224 #322
Changes from all commits
1aa51c8
b264343
a5a12a5
b35e0db
dd80885
2b23d9b
05383e7
b128ca0
cecd277
852b37f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bucket = "cdap-mgmt-tfstate-20250930180004007700000001" | ||
use_lockfile = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module "bucket_key" { | ||
source = "../key" | ||
name = "${var.name}-bucket" | ||
description = "For ${var.name} S3 bucket and its access logs" | ||
user_roles = var.cross_account_read_roles | ||
Comment on lines
-1
to
-5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change probably shouldn't be accepted until other module declaration sources of the |
||
locals { | ||
cdap_ssm = zipmap( | ||
data.aws_ssm_parameters_by_path.cdap.names, | ||
data.aws_ssm_parameters_by_path.cdap.values | ||
) | ||
access_logs_bucket = lookup(local.cdap_ssm, "/cdap/bucket-access-logs-bucket", null) | ||
} | ||
|
||
resource "aws_s3_bucket" "this" { | ||
|
@@ -99,19 +100,24 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "this" { | |
} | ||
} | ||
|
||
data "aws_iam_account_alias" "current" {} | ||
data "aws_ssm_parameters_by_path" "cdap" { | ||
path = "/cdap" | ||
recursive = true | ||
} | ||
Comment on lines
+103
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the |
||
|
||
data "aws_s3_bucket" "bucket_access_logs" { | ||
bucket = (data.aws_iam_account_alias.current.account_alias == "aws-cms-oeda-bcda-prod" | ||
? "bucket-access-logs-20250411172631068600000001" | ||
: "bucket-access-logs-20250409172631068600000001" | ||
) | ||
count = local.access_logs_bucket == null ? 0 : 1 | ||
|
||
bucket = local.access_logs_bucket | ||
} | ||
|
||
|
||
resource "aws_s3_bucket_logging" "this" { | ||
count = local.access_logs_bucket == null ? 0 : 1 | ||
|
||
bucket = aws_s3_bucket.this.id | ||
|
||
target_bucket = data.aws_s3_bucket.bucket_access_logs.id | ||
target_bucket = data.aws_s3_bucket.bucket_access_logs[0].id | ||
target_prefix = "${aws_s3_bucket.this.id}/" | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,6 @@ output "service" { | |
value = local.service | ||
} | ||
|
||
output "region_name" { | ||
description = "**Deprecated**. Use `primary_region.name`. The region name associated with the current caller identity" | ||
sensitive = false | ||
value = data.aws_region.this.name | ||
} | ||
|
||
Comment on lines
-13
to
-18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change. As noted, this was already deprecated in favor of the |
||
output "primary_region" { | ||
description = "The primary data.aws_region object from the current caller identity" | ||
sensitive = false | ||
|
@@ -29,11 +23,17 @@ output "secondary_region" { | |
} | ||
|
||
output "account_id" { | ||
description = "The AWS account ID associated with the current caller identity" | ||
description = "Deprecated. Use `aws_caller_identity.account_id`. The AWS account ID associated with the current caller identity" | ||
sensitive = true | ||
value = data.aws_caller_identity.this.account_id | ||
} | ||
Comment on lines
25
to
29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecating |
||
|
||
output "aws_caller_identity" { | ||
description = "The current data.aws_caller_identity object." | ||
sensitive = true | ||
value = data.aws_caller_identity.this | ||
} | ||
|
||
output "env" { | ||
description = "The solution's application environment name." | ||
sensitive = false | ||
|
@@ -51,3 +51,15 @@ output "default_permissions_boundary" { | |
sensitive = false | ||
value = data.aws_iam_policy.permissions_boundary | ||
} | ||
|
||
output "is_ephemeral_env" { | ||
description = "Returns true when environment is _ephemeral_, false when _established_" | ||
sensitive = false | ||
value = local.env != local.parent_env | ||
} | ||
|
||
output "parent_env" { | ||
description = "The solution's source environment. For established environments this is equal to the environment's name" | ||
sensitive = false | ||
value = local.parent_env | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# CDAP Insights Management Environment | ||
|
||
This root module configures the fundamental platform resources in the AWS DASG Insights account, including IAM, QuickSight, and SSM Parameters. | ||
|
||
## Dependencies | ||
- `services/kms-keys` | ||
- `services/bucket-access-logging` | ||
- `services/tfstate` | ||
|
||
## Bootstrapping | ||
|
||
This module is intended to serve the single `mgmt` environment. Initialization is done through the following: | ||
|
||
```sh | ||
tofu init -backend-config="../../../backends/cdap-insights-mgmt.s3.hcl" | ||
``` | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.14.1 | | ||
| <a name="provider_aws.secondary"></a> [aws.secondary](#provider\_aws.secondary) | 6.14.1 | | ||
|
||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Inputs | ||
|
||
No inputs. | ||
|
||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_sops"></a> [sops](#module\_sops) | ../../../modules/sops | n/a | | ||
| <a name="module_standards"></a> [standards](#module\_standards) | ../../../modules/standards | n/a | | ||
|
||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | ||
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | ||
| [aws_quicksight_account_settings.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_account_settings) | resource | | ||
| [aws_quicksight_ip_restriction.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/quicksight_ip_restriction) | resource | | ||
| [aws_kms_alias.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_alias) | data source | | ||
| [aws_kms_alias.secondary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_alias) | data source | | ||
|
||
<!--WARNING: GENERATED CONTENT with terraform-docs, e.g. | ||
'terraform-docs --config "$(git rev-parse --show-toplevel)/.terraform-docs.yml" .' | ||
Manually updating sections between TF_DOCS tags may be overwritten. | ||
See https://terraform-docs.io/user-guide/configuration/ for more information. | ||
--> | ||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
resource "aws_iam_role" "this" { | ||
assume_role_policy = jsonencode( | ||
{ | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole" | ||
Effect = "Allow" | ||
Principal = { | ||
Service = "quicksight.amazonaws.com" | ||
} | ||
}, | ||
] | ||
Version = "2012-10-17" | ||
} | ||
) | ||
force_detach_policies = true | ||
max_session_duration = 3600 | ||
name = "${local.service_prefix}-quicksight-service" | ||
path = "/service-role/" | ||
} | ||
|
||
# Basic Policy Attachments, Further Attachments Necessary | ||
resource "aws_iam_role_policy_attachment" "this" { | ||
for_each = toset([ | ||
"arn:aws:iam::aws:policy/service-role/AmazonSageMakerQuickSightVPCPolicy", #AWS-managed, allowing CRUD on ENIs, Limited VPC Resources | ||
"arn:aws:iam::aws:policy/service-role/AWSQuickSightListIAM", #AWS-managed, allows `iam:List*` | ||
"arn:aws:iam::aws:policy/service-role/AWSQuicksightAthenaAccess", #AWS-managed, allows access to glue, athena, and athena-related s3 resources | ||
]) | ||
|
||
role = aws_iam_role.this.name | ||
policy_arn = each.value | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
locals { | ||
app = "cdap" | ||
env = "mgmt" | ||
service = "insights" | ||
service_prefix = "${local.app}-${local.env}-${local.service}" | ||
account_id = module.standards.aws_caller_identity.id | ||
|
||
kms_key_aliases = { | ||
kms_alias_primary = data.aws_kms_alias.primary, | ||
kms_alias_secondary = data.aws_kms_alias.secondary | ||
} | ||
|
||
cdap_ssm = zipmap( | ||
data.aws_ssm_parameters_by_path.cdap.names, | ||
data.aws_ssm_parameters_by_path.cdap.values | ||
) | ||
|
||
ip_restrictions = jsondecode(lookup(nonsensitive(local.cdap_ssm), "/cdap/mgmt/insights/sensitive/ip-restrictions", "{}")) | ||
} | ||
|
||
module "standards" { | ||
source = "../../../modules/standards" #TODO: Update with appropriate reference | ||
|
||
app = local.app | ||
env = local.env | ||
root_module = "https://github.com/CMSgov/cdap/tree/main/terraform/services/insights/mgmt" | ||
service = local.service | ||
providers = { aws = aws, aws.secondary = aws.secondary } | ||
} | ||
|
||
data "aws_kms_alias" "primary" { | ||
name = "alias/${local.app}-${local.env}" | ||
} | ||
|
||
data "aws_kms_alias" "secondary" { | ||
provider = aws.secondary | ||
name = "alias/${local.app}-${local.env}" | ||
} | ||
|
||
module "sops" { | ||
source = "../../../modules/sops" #TODO: Update with appropriate reference | ||
|
||
platform = merge(module.standards, local.kms_key_aliases) | ||
} | ||
|
||
data "aws_ssm_parameters_by_path" "cdap" { | ||
path = "/cdap" | ||
recursive = true | ||
with_decryption = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resource "aws_quicksight_account_settings" "this" { | ||
aws_account_id = local.account_id | ||
default_namespace = "default" | ||
termination_protection_enabled = true | ||
} | ||
|
||
resource "aws_quicksight_ip_restriction" "this" { | ||
enabled = length(local.ip_restrictions) > 0 | ||
|
||
ip_restriction_rule_map = local.ip_restrictions | ||
|
||
depends_on = [ | ||
module.sops | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously, we don't use the
hcl
suffix on the other backends, so this is non-standard. However, this would be a nice touch to enable native highlighting/formatting in IDEs, etc.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our backends use the
*.s3.tfbackend
naming convention as recommended at https://developer.hashicorp.com/terraform/language/backend#file in order to hopefully look familiar to any engineer coming from other terraform projects. I'm not wedded to anything in the HashiCorp docs, however, and I like giving the editor hints for file formatting. Also,*.s3.hcl
is shorter, which is always a plus.