|
| 1 | +{ |
| 2 | + "Id": "2f5f8b7b-5deb-45a9-966b-bf52c6e7976c", |
| 3 | + "Name": "AWS - Find Blue-Green Target Group", |
| 4 | + "Description": "Find the online and offline target groups for a blue-green deployment", |
| 5 | + "ActionType": "Octopus.AwsRunScript", |
| 6 | + "Version": 1, |
| 7 | + "CommunityActionTemplateId": null, |
| 8 | + "Packages": [], |
| 9 | + "GitDependencies": [], |
| 10 | + "Properties": { |
| 11 | + "OctopusUseBundledTooling": "False", |
| 12 | + "Octopus.Action.Script.ScriptSource": "Inline", |
| 13 | + "Octopus.Action.Script.Syntax": "Bash", |
| 14 | + "Octopus.Action.Aws.AssumeRole": "False", |
| 15 | + "Octopus.Action.AwsAccount.UseInstanceRole": "False", |
| 16 | + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", |
| 17 | + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}", |
| 18 | + "Octopus.Action.Script.ScriptBody": "#!/bin/bash\n\nLISTENER=${1:-'#{AWSBlueGreen.AWS.ListenerARN | Trim}'}\nRULE=${2:-'#{AWSBlueGreen.AWS.RuleArn | Trim}'}\nGREENTARGETGROUP=${3:-'#{AWSBlueGreen.AWS.GreenTargetGroup | Trim}'}\nBLUETARGETGROUP=${4:-'#{AWSBlueGreen.AWS.BlueTargetGroup | Trim}'}\n\nechoerror() { echo \"$@\" 1>&2; }\n\nif ! command -v \"aws\" &> /dev/null; then\n echoerror \"You must have the AWS CLI installed for this step. Consider using a Container Image - https://octopus.com/docs/projects/steps/execution-containers-for-workers#how-to-use-execution-containers-for-workers\"\n exit 1\nfi\n\nif ! command -v \"jq\" &> /dev/null; then\n echoerror \"You must have jq installed for this step. Consider using a Container Image - https://octopus.com/docs/projects/steps/execution-containers-for-workers#how-to-use-execution-containers-for-workers\"\n exit 1\nfi\n\n# Validate the arguments\n\nif [[ -z \"${LISTENER}\" ]]; then\n echoerror \"Please provide the ARN of the listener as the first argument\"\n exit 1\nfi\n\nif [[ -z \"${RULE}\" ]]; then\n echoerror \"Please provide the ARN of the listener rule as the second argument\"\n exit 1\nfi\n\nif [[ -z \"${GREENTARGETGROUP}\" ]]; then\n echoerror \"Please provide the ARN of the green target group as the third argument\"\n exit 1\nfi\n\nif [[ -z \"${BLUETARGETGROUP}\" ]]; then\n echoerror \"Please provide the ARN of the blue target group as the fourth argument\"\n exit 1\nfi\n\n# Get the JSON representation of the listener rules\n\nRULES=$(aws elbv2 describe-rules \\\n --listener-arn \"${LISTENER}\" \\\n --output json)\n\nwrite_verbose \"${RULES}\"\n\n# Find the weight assigned to each of the target groups.\n\nGREENWEIGHT=$(jq -r \".Rules[] | select(.RuleArn == \\\"${RULE}\\\") | .Actions[] | select(.Type == \\\"forward\\\") | .ForwardConfig | .TargetGroups[] | select(.TargetGroupArn == \\\"${GREENTARGETGROUP}\\\") | .Weight\" <<< \"${RULES}\")\nBLUEWEIGHT=$(jq -r \".Rules[] | select(.RuleArn == \\\"${RULE}\\\") | .Actions[] | select(.Type == \\\"forward\\\") | .ForwardConfig | .TargetGroups[] | select(.TargetGroupArn == \\\"${BLUETARGETGROUP}\\\") | .Weight\" <<< \"${RULES}\")\n\n# Validation that we found the green and blue target groups.\n\nif [[ -z \"${GREENWEIGHT}\" ]]; then\n echoerror \"Failed to find the target group ${GREENTARGETGROUP} in the listener rule ${RULE}\"\n echoerror \"Double check that the target group exists and has been associated with the load balancer\"\n exit 1\nfi\n\nif [[ -z \"${BLUEWEIGHT}\" ]]; then\n echoerror \"Failed to find the target group ${BLUETARGETGROUP} in the listener rule ${RULE}\"\n echoerror \"Double check that the target group exists and has been associated with the load balancer\"\n exit 1\nfi\n\necho \"Green weight: ${GREENWEIGHT}\"\necho \"Blue weight: ${BLUEWEIGHT}\"\n\n# Set the output variables identifying which target group is active and which is inactive.\n# Note that we assume the target groups are either active or inactive (i.e. all traffic and no traffic).\n# Load balancers support more complex routing rules, but we assume a simple blue-green deployment.\n# If the green target group has traffic, it is considered active, and the blue target group is considered inactive.\n# If the green target group has no traffic, it is considered inactive, and the blue target group is considered active.\n\nif [ \"${GREENWEIGHT}\" != \"0\" ]; then\n echo \"Green target group is active, blue target group is inactive\"\n set_octopusvariable \"ActiveGroupArn\" \"${GREENTARGETGROUP}\"\n set_octopusvariable \"ActiveGroupColor\" \"Green\"\n set_octopusvariable \"InactiveGroupArn\" \"${BLUETARGETGROUP}\"\n set_octopusvariable \"InactiveGroupColor\" \"Blue\"\nelse\n echo \"Blue target group is active, green target group is inactive\"\n set_octopusvariable \"ActiveGroupArn\" \"${BLUETARGETGROUP}\"\n set_octopusvariable \"ActiveGroupColor\" \"Blue\"\n set_octopusvariable \"InactiveGroupArn\" \"${GREENTARGETGROUP}\"\n set_octopusvariable \"InactiveGroupColor\" \"Green\"\nfi" |
| 19 | + }, |
| 20 | + "Parameters": [ |
| 21 | + { |
| 22 | + "Id": "29cdfb7d-47fa-4c8a-837b-c58bb0d90c26", |
| 23 | + "Name": "AWSBlueGreen.AWS.Region", |
| 24 | + "Label": "Region", |
| 25 | + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", |
| 26 | + "DefaultValue": "", |
| 27 | + "DisplaySettings": { |
| 28 | + "Octopus.ControlType": "SingleLineText" |
| 29 | + } |
| 30 | + }, |
| 31 | + { |
| 32 | + "Id": "58a1ebcd-fd13-48e2-b8b9-fdfe4df8c35e", |
| 33 | + "Name": "AWSBlueGreen.AWS.Account", |
| 34 | + "Label": "Account", |
| 35 | + "HelpText": null, |
| 36 | + "DefaultValue": "", |
| 37 | + "DisplaySettings": { |
| 38 | + "Octopus.ControlType": "AmazonWebServicesAccount" |
| 39 | + } |
| 40 | + }, |
| 41 | + { |
| 42 | + "Id": "80642a7b-ef3e-4db4-b969-d0148a1baa90", |
| 43 | + "Name": "AWSBlueGreen.AWS.ListenerARN", |
| 44 | + "Label": "Listener ARN", |
| 45 | + "HelpText": null, |
| 46 | + "DefaultValue": "", |
| 47 | + "DisplaySettings": { |
| 48 | + "Octopus.ControlType": "SingleLineText" |
| 49 | + } |
| 50 | + }, |
| 51 | + { |
| 52 | + "Id": "2cf29ab4-61a1-4a80-942f-6f1dd035f634", |
| 53 | + "Name": "AWSBlueGreen.AWS.BlueTargetGroup", |
| 54 | + "Label": "Blue Target Group ARN", |
| 55 | + "HelpText": "The ARN of the blue target group. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html for more details.", |
| 56 | + "DefaultValue": "", |
| 57 | + "DisplaySettings": { |
| 58 | + "Octopus.ControlType": "SingleLineText" |
| 59 | + } |
| 60 | + }, |
| 61 | + { |
| 62 | + "Id": "b7d105c6-1640-48c4-9f01-ad9ece8d3588", |
| 63 | + "Name": "AWSBlueGreen.AWS.GreenTargetGroup", |
| 64 | + "Label": "Green Target Group ARN", |
| 65 | + "HelpText": "The ARN of the green target group. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html for more details.", |
| 66 | + "DefaultValue": "", |
| 67 | + "DisplaySettings": { |
| 68 | + "Octopus.ControlType": "SingleLineText" |
| 69 | + } |
| 70 | + }, |
| 71 | + { |
| 72 | + "Id": "ff055e9f-f223-453a-9a1f-a0238e6cdfd6", |
| 73 | + "Name": "AWSBlueGreen.AWS.RuleArn", |
| 74 | + "Label": "Rule ARN", |
| 75 | + "HelpText": "The ARN of the listener rule to update. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html for more information.", |
| 76 | + "DefaultValue": "", |
| 77 | + "DisplaySettings": { |
| 78 | + "Octopus.ControlType": "SingleLineText" |
| 79 | + } |
| 80 | + } |
| 81 | + ], |
| 82 | + "StepPackageId": "Octopus.AwsRunScript", |
| 83 | + "$Meta": { |
| 84 | + "ExportedAt": "2025-01-10T03:41:11.780Z", |
| 85 | + "OctopusVersion": "2025.1.5319", |
| 86 | + "Type": "ActionTemplate" |
| 87 | + }, |
| 88 | + "LastModifiedBy": "mcasperson", |
| 89 | + "Category": "aws" |
| 90 | +} |
0 commit comments