From 4425e6de78dd34fd31eb81434526b2edcd5e5ad5 Mon Sep 17 00:00:00 2001 From: Chris Pates Date: Tue, 8 Nov 2022 09:59:25 +0000 Subject: [PATCH] Add EnvVar Step --- cicd/EnvVarConfig/buildspec.yml | 21 ++++++++++++ cicd/cloudformation/dev-account.yaml | 49 ++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 cicd/EnvVarConfig/buildspec.yml diff --git a/cicd/EnvVarConfig/buildspec.yml b/cicd/EnvVarConfig/buildspec.yml new file mode 100644 index 00000000..ff645b1a --- /dev/null +++ b/cicd/EnvVarConfig/buildspec.yml @@ -0,0 +1,21 @@ +version: 0.2 + +phases: + install: + commands: + # Update sam to latest version + - wget -q https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip + - unzip -q awscli-exe-linux-x86_64.zip + - sudo ./aws/install --update + - rm -rf ./aws awscli-exe-linux-x86_64.zip + + pre_build: + commands: + # Print all environment variables (handy for AWS CodeBuild logs) + - env + + build: + commands: + # Set the Environment Variable to enable CodePipeline + aws lambda update-function-configuration --function-name SSOSyncFunction --environment "Variables={RUNNING_IN_CODEPIPELINE=True}" --query "Environment" + diff --git a/cicd/cloudformation/dev-account.yaml b/cicd/cloudformation/dev-account.yaml index 02cf1792..3f490224 100644 --- a/cicd/cloudformation/dev-account.yaml +++ b/cicd/cloudformation/dev-account.yaml @@ -291,13 +291,27 @@ Resources: - Name: E2ELambda InputArtifacts: - Name: Source + - Name: EnvVarConfig + ActionTypeId: + Category: Build + Owner: AWS + Version: 1 + Provider: CodeBuild + RunOrder: 2 + Configuration: + ProjectName: !Ref CodeBuildEnvVarConfig + PrimarySource: Source + OutputArtifacts: + - Name: EnvVarConfig + InputArtifacts: + - Name: Source - Name: TestCodePipeline ActionTypeId: Category: Invoke Owner: AWS Version: 1 Provider: Lambda - RunOrder: 2 + RunOrder: 3 Configuration: FunctionName: SSOSyncFunction OutputArtifacts: @@ -506,6 +520,37 @@ Resources: LogGroupName: !Ref CodePipelineLogGroup LogStreamName: !Sub "${ApplicationName}-Deploy" + CodeBuildEnvVarConfig: + Type: AWS::CodeBuild::Project + Properties: + Name: !Sub "${ApplicationName}-Set-EnvVar" + Description: !Sub Use the GitHub metadata to determine whether this commit is a release + ServiceRole: !Ref CodeBuildTestRole + Source: + Type: CODEPIPELINE + BuildSpec: "cicd/EnvVarConfig/buildspec.yml" + Environment: + ComputeType: BUILD_GENERAL1_SMALL + Image: aws/codebuild/standard:5.0 + Type: LINUX_CONTAINER + EnvironmentVariables: + - Name: FunctionName + Value: SSOSyncFunction + Artifacts: + Name: !Ref ApplicationName + Type: CODEPIPELINE + LogsConfig: + CloudWatchLogs: + GroupName: !Ref CodePipelineLogGroup + StreamName: !Ref CodeBuildEnvVarConfigLogs + Status: ENABLED + + CodeBuildEnvVarConfigLogs: + Type: AWS::Logs::LogStream + Properties: + LogGroupName: !Ref CodePipelineLogGroup + LogStreamName: !Sub "${ApplicationName}-EnvVarConfig" + CodeBuildE2ETest: Type: AWS::CodeBuild::Project Properties: @@ -541,7 +586,6 @@ Resources: LogGroupName: !Ref CodePipelineLogGroup LogStreamName: !Sub "${ApplicationName}-E2ETest" - CodePipelineRole: Type: AWS::IAM::Role Properties: @@ -603,6 +647,7 @@ Resources: - 'lambda:InvokeFunction' Resource: - !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:SSOSyncFunction + Effect: Allow CodeBuildAppRole: Type: AWS::IAM::Role