amazon-web-services - 不应用 AWS 堆栈集实例的覆盖参数

标签 amazon-web-services aws-cloudformation

下面的 CF 模板经过缩进,用于创建一个堆栈集,其中包含一个具有特定参数值的角色,具体取决于帐户所在的 OU。因此,如果帐户位于/创建于 OU A 中,则调试角色的信任关系必须指向帐户“111111111111”。

AWSTemplateFormatVersion: "2010-09-09"
Description: Debug Role
Resources:
  StackSet:
    Type: AWS::CloudFormation::StackSet
    Properties:
      Description: Debug Role Stack Set
      PermissionModel: SERVICE_MANAGED
      Capabilities:
        - CAPABILITY_NAMED_IAM
      AutoDeployment:
        Enabled: true
        RetainStacksOnAccountRemoval: false
      Parameters:
        - ParameterKey: TrustAccountId
          ParameterValue: "123456789123" # default value
      OperationPreferences:
        RegionConcurrencyType: PARALLEL
        FailureToleranceCount: 0
        MaxConcurrentPercentage: 100
      StackInstancesGroup:
        - DeploymentTargets:
            OrganizationalUnitIds:
              - ou-aaaa  # A
          ParameterOverrides:
            - ParameterKey: "TrustAccountId"
              ParameterValue: "111111111111"
          Regions:
            - 'eu-central-1'
        - DeploymentTargets:
            OrganizationalUnitIds:
              - ou-bbbb  # B
          ParameterOverrides:
            - ParameterKey: "TrustAccountId"
              ParameterValue: "222222222222"
          Regions:
            - 'eu-central-1'
      StackSetName: debug-role-stack-set
      TemplateBody: |
        AWSTemplateFormatVersion: 2010-09-09
        Description: Debug Role
        Parameters:
          TrustAccountId:
            Description: Trust to account
            Type: String
            AllowedPattern: \d{12}
        Resources:
          DebugRole:
            Type: AWS::IAM::Role
            Description: "Role for debugging accounts"
            Properties:
              RoleName: DebugRole
              Path: /
              AssumeRolePolicyDocument:
                Version: "2012-10-17"
                Statement:
                  - Effect: Allow
                    Principal:
                      AWS:
                        - Ref: TrustAccountId
                    Action:
                      - 'sts:AssumeRole'
              ManagedPolicyArns:
                - arn:aws:iam::aws:policy/AdministratorAccess

现在的问题是,堆栈实例组中的所有帐户,无论是现有帐户还是新帐户,都会使用默认参数值“123456789123”应用堆栈。因此,所有帐户都会获得与“123456789123”具有不正确信任关系的角色。

根据 OU 应用正确值的唯一方法是使用 CLI 更新堆栈实例。

aws cloudformation update-stack-instances --stack-set-name debug-role-stack-set --deployment-targets OrganizationalUnitIds=ou-aaaa --regions eu-central-1 --operation-preferences FailureToleranceCount=0,MaxConcurrentCount=5 --parameter-overrides Pa
rameterKey=TrustAccountId,ParameterValue=111111111111

有没有办法在堆栈创建期间应用正确的参数值,而无需事后更新它们?因为对于每个新帐户,所有堆栈集实例都需要更新。

最佳答案

由于未使用正确的参数值执行堆栈实例,因此我最终为每个 OU 设置了一个堆栈。当然,这种方案只适用于静态环境。因此,就我而言,如果弹出新的 OU,则必须创建新的堆栈集。

关于amazon-web-services - 不应用 AWS 堆栈集实例的覆盖参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69159914/

相关文章:

amazon-web-services - AWS Cloudformation - 安全组模板错误

amazon-web-services - AWS Lambda 意外无限循环后的令人担忧的行为

amazon-web-services - 在 API Gateway 中设置查询字符串和 header 的名称

amazon-web-services - CloudFormation 中的条件 Dynamo 全局表

amazon-web-services - 如何确保 AWS Cloudformation 更新期间资源删除/创建顺序

aws-cloudformation - 如何从我的 AWS SAM 模板获取自动生成 Rest Api?在另一个 SAM 模板中使用

java - AWS 上的 HTML5 和 Java 服务器应用程序部署

macos - 使用端口转发从本地 Web 浏览器访问 EC2 Ubuntu 实例的本地主机地址

amazon-web-services - 错误: "Conditions must be prefaced by a vendor." on creating Role in AWS CDK

node.js - 无服务器 : Deploy to same api from different yml