{
  "Description": "(SO0320-installer) Modern Data Architecture Accelerator. Version 1.8.1",
  "Metadata": {
    "AWS::CloudFormation::Interface": {
      "ParameterGroups": [
        {
          "Label": {
            "default": "GitHub Repository Configuration"
          },
          "Parameters": [
            "RepositoryBranchName"
          ]
        },
        {
          "Label": {
            "default": "MDAA Configuration"
          },
          "Parameters": [
            "SampleName",
            "OrgName",
            "MdaaVersion"
          ]
        },
        {
          "Label": {
            "default": "Network Configuration"
          },
          "Parameters": [
            "VpcId",
            "SubnetId"
          ]
        }
      ],
      "ParameterLabels": {
        "RepositoryBranchName": {
          "default": "GitHub Branch Name"
        },
        "SampleName": {
          "default": "MDAA Sample Configuration"
        },
        "OrgName": {
          "default": "Organization Name (Required)"
        },
        "MdaaVersion": {
          "default": "MDAA Version"
        },
        "VpcId": {
          "default": "VPC ID"
        },
        "SubnetId": {
          "default": "Subnet ID"
        }
      }
    }
  },
  "Parameters": {
    "RepositoryBranchName": {
      "Type": "String",
      "Default": "release/v1.8.1",
      "AllowedPattern": ".+",
      "ConstraintDescription": "Repository Branch Name is required",
      "Description": "The name of the branch (e.g., \"main\")"
    },
    "SampleName": {
      "Type": "String",
      "Default": "basic_datalake",
      "AllowedValues": [
        "basic_datalake",
        "basic_datascience_platform"
      ],
      "Description": "MDAA Sample you want to deploy"
    },
    "OrgName": {
      "Type": "String",
      "AllowedPattern": "^[a-z][a-z0-9-]{0,99}$",
      "ConstraintDescription": "Org Name must start with a lowercase letter and contain only lowercase alphanumeric characters and hyphens. Maximum length is 100 characters.",
      "Description": "An MDAA deployment requires an Org Name (must start with a lowercase letter, contain only lowercase alphanumeric characters and hyphens, and be 100 characters or less)"
    },
    "MdaaVersion": {
      "Type": "String",
      "Default": "latest",
      "AllowedPattern": "^(latest|[0-9]+(\\.[0-9]+)*)$",
      "ConstraintDescription": "Must be \"latest\" or a version with numbers and dots only (e.g., 1.3.0)",
      "Description": "Version of the MDAA modules to deploy (e.g., \"latest\", \"1.3.0\"). This version needs to be compatible with the branch you are selecting"
    },
    "VpcId": {
      "Type": "AWS::EC2::VPC::Id",
      "Description": "The ID of the VPC to use for deployment. Required for resources that need network access."
    },
    "SubnetId": {
      "Type": "AWS::EC2::Subnet::Id",
      "Description": "The ID of the subnet to use for deployment. Must be a subnet within the selected VPC. Required for resources that need network access."
    }
  },
  "Rules": {
    "ValidateOrganizationName": {
      "Assertions": [
        {
          "Assert": {
            "Fn::Not": [
              {
                "Fn::Equals": [
                  {
                    "Ref": "OrgName"
                  },
                  ""
                ]
              }
            ]
          },
          "AssertDescription": "Organization Name is required for all MDAA deployments"
        }
      ]
    },
    "ValidateNetworkParametersForDataScience": {
      "RuleCondition": {
        "Fn::Equals": [
          {
            "Ref": "SampleName"
          },
          "basic_datascience_platform"
        ]
      },
      "Assertions": [
        {
          "Assert": {
            "Fn::Not": [
              {
                "Fn::Equals": [
                  {
                    "Ref": "VpcId"
                  },
                  ""
                ]
              }
            ]
          },
          "AssertDescription": "VPC ID is required."
        },
        {
          "Assert": {
            "Fn::Not": [
              {
                "Fn::Equals": [
                  {
                    "Ref": "SubnetId"
                  },
                  ""
                ]
              }
            ]
          },
          "AssertDescription": "Subnet ID is required."
        }
      ]
    }
  },
  "Resources": {
    "InstallerKey2A6A8C6D": {
      "Type": "AWS::KMS::Key",
      "Properties": {
        "Description": "Key used for encryption of CodeBuild artifacts",
        "EnableKeyRotation": true,
        "KeyPolicy": {
          "Statement": [
            {
              "Action": "kms:*",
              "Effect": "Allow",
              "Principal": {
                "AWS": {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":iam::",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":root"
                    ]
                  ]
                }
              },
              "Resource": "*"
            }
          ],
          "Version": "2012-10-17"
        }
      },
      "UpdateReplacePolicy": "Retain",
      "DeletionPolicy": "Retain",
      "Metadata": {
        "aws:cdk:path": "MdaaInstallerStack/InstallerKey/Resource"
      }
    },
    "BuildRole41B77417": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": "codebuild.amazonaws.com"
              }
            }
          ],
          "Version": "2012-10-17"
        },
        "ManagedPolicyArns": [
          {
            "Fn::Join": [
              "",
              [
                "arn:",
                {
                  "Ref": "AWS::Partition"
                },
                ":iam::aws:policy/AdministratorAccess"
              ]
            ]
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "MdaaInstallerStack/BuildRole/Resource"
      }
    },
    "BuildRoleDefaultPolicy05D1D9FE": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyDocument": {
          "Statement": [
            {
              "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
              ],
              "Effect": "Allow",
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":logs:",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":log-group:/aws/codebuild/",
                      {
                        "Ref": "GitHubBuildProject4A7606D3"
                      },
                      ":*"
                    ]
                  ]
                },
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":logs:",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":log-group:/aws/codebuild/",
                      {
                        "Ref": "GitHubBuildProject4A7606D3"
                      }
                    ]
                  ]
                }
              ]
            },
            {
              "Action": [
                "codebuild:BatchPutCodeCoverages",
                "codebuild:BatchPutTestCases",
                "codebuild:CreateReport",
                "codebuild:CreateReportGroup",
                "codebuild:UpdateReport"
              ],
              "Effect": "Allow",
              "Resource": {
                "Fn::Join": [
                  "",
                  [
                    "arn:",
                    {
                      "Ref": "AWS::Partition"
                    },
                    ":codebuild:",
                    {
                      "Ref": "AWS::Region"
                    },
                    ":",
                    {
                      "Ref": "AWS::AccountId"
                    },
                    ":report-group/",
                    {
                      "Ref": "GitHubBuildProject4A7606D3"
                    },
                    "-*"
                  ]
                ]
              }
            },
            {
              "Action": [
                "kms:Decrypt",
                "kms:Encrypt",
                "kms:GenerateDataKey*",
                "kms:ReEncrypt*"
              ],
              "Effect": "Allow",
              "Resource": {
                "Fn::GetAtt": [
                  "InstallerKey2A6A8C6D",
                  "Arn"
                ]
              }
            }
          ],
          "Version": "2012-10-17"
        },
        "PolicyName": "BuildRoleDefaultPolicy05D1D9FE",
        "Roles": [
          {
            "Ref": "BuildRole41B77417"
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "MdaaInstallerStack/BuildRole/DefaultPolicy/Resource"
      }
    },
    "GitHubBuildProject4A7606D3": {
      "Type": "AWS::CodeBuild::Project",
      "Properties": {
        "Artifacts": {
          "Type": "NO_ARTIFACTS"
        },
        "Cache": {
          "Type": "NO_CACHE"
        },
        "EncryptionKey": {
          "Fn::GetAtt": [
            "InstallerKey2A6A8C6D",
            "Arn"
          ]
        },
        "Environment": {
          "ComputeType": "BUILD_GENERAL1_SMALL",
          "EnvironmentVariables": [
            {
              "Name": "REPOSITORY_BRANCH_NAME",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "RepositoryBranchName"
              }
            },
            {
              "Name": "SAMPLE_NAME",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "SampleName"
              }
            },
            {
              "Name": "SAMPLE_CONFIG_FOLDER",
              "Type": "PLAINTEXT",
              "Value": "starter_kits"
            },
            {
              "Name": "ORG_NAME",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "OrgName"
              }
            },
            {
              "Name": "VPC_ID",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "VpcId"
              }
            },
            {
              "Name": "SUBNET_ID",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "SubnetId"
              }
            },
            {
              "Name": "MDAA_VERSION",
              "Type": "PLAINTEXT",
              "Value": {
                "Ref": "MdaaVersion"
              }
            }
          ],
          "Image": "aws/codebuild/standard:7.0",
          "ImagePullCredentialsType": "CODEBUILD",
          "PrivilegedMode": true,
          "Type": "LINUX_CONTAINER"
        },
        "Name": {
          "Fn::Join": [
            "",
            [
              "MDAA-Build-",
              {
                "Ref": "SampleName"
              }
            ]
          ]
        },
        "ServiceRole": {
          "Fn::GetAtt": [
            "BuildRole41B77417",
            "Arn"
          ]
        },
        "Source": {
          "BuildSpec": "{\n  \"version\": 0.2,\n  \"phases\": {\n    \"install\": {\n      \"runtime-versions\": {\n        \"nodejs\": 22\n      },\n      \"commands\": [\n        \"git clone --branch $REPOSITORY_BRANCH_NAME --single-branch https://github.com/aws/modern-data-architecture-accelerator.git\"\n      ]\n    },\n    \"build\": {\n      \"commands\": [\n        \"set -e\",\n        \"cd modern-data-architecture-accelerator\",\n        \"npm install -g aws-cdk @aws-mdaa/cli@${MDAA_VERSION}\",\n        \"echo \\\"Starting build phase...\\\"\",\n        \"export CDK_DEFAULT_REGION=$(aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].RegionName')\",\n        \"export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query 'Account' --output text)\",\n        \"export CDK_NEW_BOOTSTRAP=1 && aws cloudformation describe-stacks --stack-name CDKToolkit || npx cdk bootstrap aws://${CDK_DEFAULT_ACCOUNT}/${CDK_DEFAULT_REGION}\",\n        \"echo \\\"org: ${ORG_NAME}\\\"\",\n        \"echo \\\"Replacing org-name place holder\\\"\",\n        \"echo using sample: ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/mdaa.yaml\",\n        \"sed -i 's/<unique[- ]org[- ]name>/'\\\"$ORG_NAME\\\"'/g' ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/mdaa.yaml\",\n        \"find ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/ -type f \\\\( -name \\\"*.yaml\\\" -o -name \\\"*.yml\\\" \\\\) -exec sed -i 's/<your vpc id>/'\\\"$VPC_ID\\\"'/g' {} \\\\;\",\n        \"find ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/ -type f \\\\( -name \\\"*.yaml\\\" -o -name \\\"*.yml\\\" \\\\) -exec sed -i 's/<your subnet id>/'\\\"$SUBNET_ID\\\"'/g' {} \\\\;\",\n        \"find ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/ -type f \\\\( -name \\\"*.yaml\\\" -o -name \\\"*.yml\\\" \\\\) -exec sed -i 's/<your datascience team name>/'\\\"$ORG_NAME\\\"'-datascience-team/g' {} \\\\;\",\n        \"sed -i 's/^region: default$/region: '\\\"$CDK_DEFAULT_REGION\\\"'/' ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/mdaa.yaml\",\n        \"mdaa -c ${SAMPLE_CONFIG_FOLDER}/${SAMPLE_NAME}/mdaa.yaml --mdaa_version ${MDAA_VERSION} deploy\",\n        \"echo \\\"Deployment completed successfully\\\"\"\n      ]\n    }\n  }\n}",
          "Type": "NO_SOURCE"
        }
      },
      "Metadata": {
        "aws:cdk:path": "MdaaInstallerStack/GitHubBuildProject/Resource"
      }
    },
    "CDKMetadata": {
      "Type": "AWS::CDK::Metadata",
      "Properties": {
        "Analytics": "v2:deflate64:H4sIAAAAAAAA/41SXWvbMBT9LdVjUbzWgz3kzU3DCElb42R7CSMo0m2mRJaMdJVihP/7kGxnK2GlT9K9555zP/Ms/3af3d2wNzfh4jRRcp+FNTJ+orNXXTLLakCw0ai8Asre3C6capeFJbTbQECzvYIltJVBhtJoMkXrgRIBjlvZ9C5yS7pfUWMJbUclq7NQGQXbQJhzvgbx0JJpII2VmsuGqYJz4zUmIh1iIqHgf/UoqZlmBxClUZJLcGS6De98bWHH3B0NhAmxMeWYoo+InAFFZPz3Qiup4YKRW/IJ8GPd/6NpIrEt2ruj4iXZxkTkqoZrtxBrZAg1aHTv0n7WncroK+goNwL2XiqRhdKaI3Dcxr2k3zOrYVgJ6LO0RkeZuLjEWNTsANHCthnjBLwyr3Bm6sYjbHrg4cdi9bj7Pn+eV8Xqfrd+KlYrQomM/IUYmMkqvVKX2Q3s2cvjPCkQShxwC+ie0tLtzIIAjZIpN4hYaIyTaGw73kxj5VkqOIDoD7WLvXDbpkNdQjsS05DTN/W2boBft/6TWRnP3/1z4cPUui4aLx4bjx3VRkB2dF/OeZ7lX7P85uiknFivUdaQVf37ByVU6BiLAwAA"
      },
      "Metadata": {
        "aws:cdk:path": "MdaaInstallerStack/CDKMetadata/Default"
      },
      "Condition": "CDKMetadataAvailable"
    }
  },
  "Outputs": {
    "CodeBuildProjectUrl": {
      "Description": "Click to open the CodeBuild project. Then click \"Start build\" to begin the MDAA deployment.",
      "Value": {
        "Fn::Join": [
          "",
          [
            "https://",
            {
              "Ref": "AWS::Region"
            },
            ".console.aws.amazon.com/codesuite/codebuild/projects/",
            {
              "Ref": "GitHubBuildProject4A7606D3"
            },
            "/build-history?region=",
            {
              "Ref": "AWS::Region"
            }
          ]
        ]
      }
    },
    "CodeBuildProjectName": {
      "Description": "Name of the CodeBuild project",
      "Value": {
        "Ref": "GitHubBuildProject4A7606D3"
      }
    }
  },
  "Conditions": {
    "CDKMetadataAvailable": {
      "Fn::Or": [
        {
          "Fn::Or": [
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "af-south-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-east-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-northeast-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-northeast-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-northeast-3"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-south-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-south-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-southeast-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-southeast-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-southeast-3"
              ]
            }
          ]
        },
        {
          "Fn::Or": [
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ap-southeast-4"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ca-central-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "ca-west-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "cn-north-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "cn-northwest-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-central-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-central-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-north-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-south-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-south-2"
              ]
            }
          ]
        },
        {
          "Fn::Or": [
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-west-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-west-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "eu-west-3"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "il-central-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "me-central-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "me-south-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "sa-east-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "us-east-1"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "us-east-2"
              ]
            },
            {
              "Fn::Equals": [
                {
                  "Ref": "AWS::Region"
                },
                "us-west-1"
              ]
            }
          ]
        },
        {
          "Fn::Equals": [
            {
              "Ref": "AWS::Region"
            },
            "us-west-2"
          ]
        }
      ]
    }
  }
}