aws-samples / aws-secure-environment-accelerator

The AWS Secure Environment Accelerator is a tool designed to help deploy and operate secure multi-account, multi-region AWS environments on an ongoing basis. The power of the solution is the configuration file which enables the completely automated deployment of customizable architectures within AWS without changing a single line of code.
Apache License 2.0
725 stars 233 forks source link

[Enhancement] auto-replace variables in scp/config file #615

Closed Brian969 closed 3 years ago

Brian969 commented 3 years ago

Describe the problem you want solved

Describe the solution you'd like

Example - These lines in SCP's: "arn:aws:iam::*:role/${ACCELERATOR_PREFIX}*", "arn:aws:iam::*:role/${ACCELERATOR_NAME}Ops-*" "ec2:ResourceTag/Accel-P": "${ACCELERATOR_NAME}" "Resource": ["arn:aws:s3:::${ACCELERATOR_PREFIX_LND}-*", "arn:aws:s3:::cdktoolkit-*", "arn:aws:s3:::cf-templates-*"], "arn:aws:ssm:*:*:parameter/${ACCELERATOR_PREFIX_ND}*", "Resource": "arn:aws:iam::*:role/${ACCELERATOR_PREFIX}RDGW-Role", "Resource": "arn:aws:logs:::log-group:*${ACCELERATOR_PREFIX_ND}*", "Resource": ["arn:aws:firehose:*:*:deliverystream/${ACCELERATOR_PREFIX_ND}*", "arn:aws:kinesis:*:*:stream/${ACCELERATOR_PREFIX_ND}*"],

Would transform to these: "arn:aws:iam::*:role/PBMMAccel-*", "arn:aws:iam::*:role/PBMMOps-*" "ec2:ResourceTag/Accel-P": "PBMM" "Resource": ["arn:aws:s3:::pbmmaccel-*", "arn:aws:s3:::cdktoolkit-*", "arn:aws:s3:::cf-templates-*"], "arn:aws:ssm:*:*:parameter/PBMMAccel*", "Resource": "arn:aws:iam::*:role/PBMMAccel-RDGW-Role", "Resource": "arn:aws:logs:::log-group:*PBMMAccel*", "Resource": ["arn:aws:firehose:*:*:deliverystream/PBMMAccel*", "arn:aws:kinesis:*:*:stream/PBMMAccel*"],

(need to think about quote handling on regions - does it make sense? Should it be a string rather than an array to enable this?)

ADDITIONALLY

Brian969 commented 3 years ago

For reference: '\${HOME_REGION}': region, '\${GBL_REGION}': GLOBAL_REGION, '\${ACCELERATOR_NAME}': acceleratorName, '\${ACCELERATOR_PREFIX}': acceleratorPrefix, '\${ACCELERATOR_PREFIX_ND}': accelPrefixNd, '\${ACCELERATOR_PREFIX_LND}': accelPrefixNd.toLowerCase(), '\${ORG_ADMIN_ROLE}': orgAdminRole!,

Brian969 commented 3 years ago

#### PROBLEM1 - it failed to replace ${ORG_ADMIN_ROLE} in the SCP's - first run succeeds, second run fails due to SCP blocks. - weird - on re-examination, problem1 may not be an issue. #### PROBLEM 2 - double variables not properly replacing quotes ~~- "aws:RequestedRegion": "${ADDL_REGIONS_A}" replaced with: "aws:RequestedRegion": ["ca-central-1, us-east-1"] instead of: "aws:RequestedRegion": ["ca-central-1", "us-east-1"]~~ - and this in the _C case: "aws:RequestedRegion": ["ca-central-1, us-east-1", "us-east-2", "us-west-1", "us-west-2"] - missing two sets of quotes between ca-central-1 and us-east-1 - operator error, reformatted input file

QUESTION: