У меня есть шаблон AWS CloudFormation CodeBuild, в который я хотел бы передать массив переменных среды в качестве параметров, чтобы я мог повторно использовать шаблон для нескольких проектов CloudFormation.
Я бы хотел передать этот раздел в качестве параметра.Как мне это сделать?
"environmentVariables": [{
"name": "$S3_BUCKET",
"value": "Parameter_Store_Variable_name",
"type": "PARAMETER_STORE"}
],
Вот еще шаблон для большего контекста ...
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Automate provisioning of CodeBuild with CodePipeline CodeCommit and CodeDeploy.",
"Parameters": {
"SourceLocation": {
"Type": "String",
"Description": "https://github.com/<account>/<repo>"
},
"AppName": {
"Type": "String",
"Description": "Name of the application."
}
},
"Resources": {
"CodeBuild": {
"Type": "AWS::CodeBuild::Project",
"DependsOn": "CodeBuildRole",
"Properties": {
"name": "test-project-name",
"description": "description",
"source": {
"type": "GITHUB",
"location": {
"Ref": "SourceLocation"
},
"gitCloneDepth": 1,
"buildspec": "",
"badgeEnabled": true,
"auth": {
"type": "OAUTH"
}
},
"artifacts": {
"type": "artifacts-type",
"location": "artifacts-location",
"path": "path",
"namespaceType": "namespaceType",
"name": "artifacts-name",
"packaging": "packaging"
},
"cache": {
"type": "NONE"
},
"ServiceRole": {
"Ref": "CodeBuildRole"
},
"timeoutInMinutes": 10,
"environment": {
"type": "LINUX_CONTAINER",
"image": "aws/codebuild/nodejs:8.11.0",
"computeType": "BUILD_GENERAL1_SMALL",
"environmentVariables": [{
"name": "$S3_BUCKET",
"value": "PARAMETERSTOREVARIABLENAMEHERE",
"type": "PARAMETER_STORE"
}],
"privilegedMode": false
}
}
},
"CodeBuildRole": {
"Description": "Creating service role in IAM for AWS CodeBuild",
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::Sub": "codebuild-role-${AppName}"
},
"AssumeRolePolicyDocument": {
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"codebuild.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}]
},
"Path": "/"
}
},
"CodeBuildPolicy": {
"Type": "AWS::IAM::Policy",
"DependsOn": "CodeBuildRole",
"Description": "Setting IAM policy for the service role for AWS CodeBuild",
"Properties": {
"PolicyName": {
"Fn::Sub": "codebuild-policy-${AppName}"
},
"PolicyDocument": {
"Statement": [{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"s3:*"
]
},
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"kms:GenerateDataKey*",
"kms:Encrypt",
"kms:Decrypt"
]
},
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"sns:SendMessage"
]
}
]
},
"Roles": [{
"Ref": "CodeBuildRole"
}]
}
}
},
"Outputs": {
"CodeBuildURL": {
"Description": "CodeBuild URL",
"Value": {
"Fn::Join": [
"", [
"https://console.aws.amazon.com/codebuild/home?region=",
{
"Ref": "AWS::Region"
},
"#/projects/",
{
"Ref": "CodeBuild"
},
"/view"
]
]
}
}
}
}
Спасибо за помощь!