diff --git a/step-templates/aws-find-blue-green-asg.json b/step-templates/aws-find-blue-green-asg.json new file mode 100644 index 00000000..be78d07e --- /dev/null +++ b/step-templates/aws-find-blue-green-asg.json @@ -0,0 +1,80 @@ +{ + "Id": "6b72995e-500c-4b4b-9121-88f3a988ec71", + "Name": "AWS - Find Blue-Green ASG", + "Description": "Return the name of the online and offline blue and green Auto Scaling Groups", + "ActionType": "Octopus.AwsRunScript", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "OctopusUseBundledTooling": "False", + "Octopus.Action.Script.ScriptSource": "Inline", + "Octopus.Action.Script.Syntax": "Bash", + "Octopus.Action.Aws.AssumeRole": "False", + "Octopus.Action.AwsAccount.UseInstanceRole": "False", + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", + "Octopus.Action.Script.ScriptBody": "#!/bin/bash\n\nINACTIVECOLOR=${1:-'#{AWSBlueGreen.InactiveColor | Trim}'}\nGREENASG=${2:-'#{AWSBlueGreen.AWS.GreenASG | Trim}'}\nBLUEASG=${3:-'#{AWSBlueGreen.AWS.BlueASG | Trim}'}\n\nechoerror() { echo \"$@\" 1>&2; }\n\nif [[ -z \"${INACTIVECOLOR}\" ]]\nthen\n echoerror \"Please provide the color of the inactive Auto Scaling group (Green or Blue) as the first argument\"\n exit 1\nfi\n\nif [[ -z \"${GREENASG}\" ]]\nthen\n echoerror \"Please provide the name of the Green Auto Scaling group as the second argument\"\n exit 1\nfi\n\nif [[ -z \"${BLUEASG}\" ]]\nthen\n echoerror \"Please provide the name of the Blue Auto Scaling group as the third argument\"\n exit 1\nfi\n\nif [[ \"${INACTIVECOLOR^^}\" == \"GREEN\" ]]\nthen\n set_octopusvariable \"ActiveGroup\" \"${BLUEASG}\"\n set_octopusvariable \"InactiveGroup\" \"${GREENASG}\"\n echo \"Active group is Blue (${BLUEASG}), inactive group is Green (${GREENASG})\"\nelse\n set_octopusvariable \"ActiveGroup\" \"${GREENASG}\"\n set_octopusvariable \"InactiveGroup\" \"${BLUEASG}\"\n echo \"Active group is Green (${GREENASG}), inactive group is Blue (${BLUEASG})\"\nfi", + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}" + }, + "Parameters": [ + { + "Id": "f8522014-f1ba-4e4a-a06d-59ebdba6f276", + "Name": "AWSBlueGreen.InactiveColor", + "Label": "Inactive Color", + "HelpText": "The color of the inactive group (Green or Blue). This value is usually found from the \"AWS - Find Blue-Green Target Group\" step.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "8753e6ed-0ae6-4a4c-ae5b-155139037633", + "Name": "AWSBlueGreen.AWS.GreenASG", + "Label": "Green ASG Name", + "HelpText": "The name of the green auto scaler group. See https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-groups.html for more details.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "bf9187f5-62e9-4ad9-b53f-459466b84994", + "Name": "AWSBlueGreen.AWS.BlueASG", + "Label": "Blue ASG Name", + "HelpText": "The name of the blue auto scaler group. See https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-groups.html for more details.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "eb02bbf2-e05a-4469-9359-c77d77d87dd2", + "Name": "AWSBlueGreen.AWS.Region", + "Label": "Region", + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "99a74afc-ee67-4295-8281-3bb1c6e83d06", + "Name": "AWSBlueGreen.AWS.Account", + "Label": "Account", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "AmazonWebServicesAccount" + } + } + ], + "StepPackageId": "Octopus.AwsRunScript", + "$Meta": { + "ExportedAt": "2025-01-10T03:42:14.665Z", + "OctopusVersion": "2025.1.5319", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "mcasperson", + "Category": "aws" +} diff --git a/step-templates/aws-find-blue-green-target-group.json b/step-templates/aws-find-blue-green-target-group.json new file mode 100644 index 00000000..b4a611d1 --- /dev/null +++ b/step-templates/aws-find-blue-green-target-group.json @@ -0,0 +1,90 @@ +{ + "Id": "2f5f8b7b-5deb-45a9-966b-bf52c6e7976c", + "Name": "AWS - Find Blue-Green Target Group", + "Description": "Find the online and offline target groups for a blue-green deployment", + "ActionType": "Octopus.AwsRunScript", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "OctopusUseBundledTooling": "False", + "Octopus.Action.Script.ScriptSource": "Inline", + "Octopus.Action.Script.Syntax": "Bash", + "Octopus.Action.Aws.AssumeRole": "False", + "Octopus.Action.AwsAccount.UseInstanceRole": "False", + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}", + "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" + }, + "Parameters": [ + { + "Id": "29cdfb7d-47fa-4c8a-837b-c58bb0d90c26", + "Name": "AWSBlueGreen.AWS.Region", + "Label": "Region", + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "58a1ebcd-fd13-48e2-b8b9-fdfe4df8c35e", + "Name": "AWSBlueGreen.AWS.Account", + "Label": "Account", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "AmazonWebServicesAccount" + } + }, + { + "Id": "80642a7b-ef3e-4db4-b969-d0148a1baa90", + "Name": "AWSBlueGreen.AWS.ListenerARN", + "Label": "Listener ARN", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "2cf29ab4-61a1-4a80-942f-6f1dd035f634", + "Name": "AWSBlueGreen.AWS.BlueTargetGroup", + "Label": "Blue Target Group ARN", + "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.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "b7d105c6-1640-48c4-9f01-ad9ece8d3588", + "Name": "AWSBlueGreen.AWS.GreenTargetGroup", + "Label": "Green Target Group ARN", + "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.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "ff055e9f-f223-453a-9a1f-a0238e6cdfd6", + "Name": "AWSBlueGreen.AWS.RuleArn", + "Label": "Rule ARN", + "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.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + } + ], + "StepPackageId": "Octopus.AwsRunScript", + "$Meta": { + "ExportedAt": "2025-01-10T03:41:11.780Z", + "OctopusVersion": "2025.1.5319", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "mcasperson", + "Category": "aws" +} diff --git a/step-templates/aws-initiate-instance-refresh.json b/step-templates/aws-initiate-instance-refresh.json new file mode 100644 index 00000000..7bf44df2 --- /dev/null +++ b/step-templates/aws-initiate-instance-refresh.json @@ -0,0 +1,61 @@ +{ + "Id": "150c46d1-f33f-493b-a8c6-f5bd22f540f3", + "Name": "AWS - Initiate Instance Refresh", + "Description": "Initiates an instance refresh for an Auto Scaling group and waits for it to complete.", + "ActionType": "Octopus.AwsRunScript", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "OctopusUseBundledTooling": "False", + "Octopus.Action.Script.ScriptSource": "Inline", + "Octopus.Action.Script.Syntax": "Bash", + "Octopus.Action.Aws.AssumeRole": "False", + "Octopus.Action.AwsAccount.UseInstanceRole": "False", + "Octopus.Action.RunOnServer": "true", + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}", + "Octopus.Action.Script.ScriptBody": "#!/bin/bash\n\nASG=${1:-'#{AWSBlueGreen.AWS.ASG | 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\nif [[ -z \"${ASG}\" ]]; then\n echoerror \"Please provide the name of the Auto Scaling group as the first argument\"\n exit 1\nfi\n\nfor i in {1..30}; do\n EXISTINGREFRESHES=$(aws autoscaling describe-instance-refreshes --auto-scaling-group-name \"${ASG}\")\n NOTSUCCESSFUL=$(jq '.InstanceRefreshes[] | select(.Status == \"Pending\" or .Status == \"InProgress\" or .Status == \"Cancelling\" or .Status == \"RollbackInProgress\" or .Status == \"Baking\")' <<< \"${EXISTINGREFRESHES}\")\n if [[ -z \"${NOTSUCCESSFUL}\" ]];\n then\n break\n fi\n echo \"Waiting for existing Auto Scaling group ${ASG} refresh to complete...\"\n sleep 12\ndone\n\nREFRESH=$(aws autoscaling start-instance-refresh --auto-scaling-group-name \"${ASG}\")\n\nif [[ $? -ne 0 ]];\nthen\n echoerror \"Failed to start instance refresh for Auto Scaling group ${ASG}\"\n exit 1\nfi\n\nREFRESHTOKEN=$(jq -r '.InstanceRefreshId' <<< \"${REFRESH}\")\n\necho \"Refreshing instances in Auto Scaling group ${ASG}...\"\n\nwrite_verbose \"${REFRESH}\"\n\n# Wait for all instances to be healthy\nfor i in {1..30}; do\n REFRESHSTATUS=$(aws autoscaling describe-instance-refreshes --auto-scaling-group-name \"${ASG}\" --instance-refresh-ids \"${REFRESHTOKEN}\")\n STATUS=$(jq -r '.InstanceRefreshes[0].Status' <<< \"${REFRESHSTATUS}\")\n PERCENTCOMPLETE=$(jq -r '.InstanceRefreshes[0].PercentageComplete' <<< \"${REFRESHSTATUS}\")\n\n # Treat a null percentage as 0\n if [[ \"${PERCENTCOMPLETE}\" == \"null\" ]]\n then\n PERCENTCOMPLETE=0\n fi\n\n write_verbose \"${REFRESHSTATUS}\"\n\n if [[ \"${STATUS}\" == \"Successful\" ]]\n then\n echo \"Instance refresh succeeded\"\n break\n elif [[ \"${STATUS}\" == \"Failed\" ]];\n then\n echo \"Instance refresh failed!\"\n exit 1\n fi\n echo \"Waiting for Auto Scaling group ${ASG} refresh to complete (${STATUS} ${PERCENTCOMPLETE}%)...\"\n sleep 12\ndone" + }, + "Parameters": [ + { + "Id": "2fe001f5-39ee-40d9-b104-24817759ac6f", + "Name": "AWSBlueGreen.AWS.Region", + "Label": "AWS Region", + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "f3630bb5-ab07-46b4-b764-19f1c3b2ec5f", + "Name": "AWSBlueGreen.AWS.Account", + "Label": "Account", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "AmazonWebServicesAccount" + } + }, + { + "Id": "bdfdedee-fdeb-4292-96fd-e41c64b1e523", + "Name": "AWSBlueGreen.AWS.ASG", + "Label": "ASG Name", + "HelpText": "The name of the auto scaler group to refresh. See https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-groups.html for more details.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + } + ], + "StepPackageId": "Octopus.AwsRunScript", + "$Meta": { + "ExportedAt": "2025-01-10T04:12:22.681Z", + "OctopusVersion": "2025.1.5319", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "mcasperson", + "Category": "aws" +} diff --git a/step-templates/aws-set-blue-green-target-group.json b/step-templates/aws-set-blue-green-target-group.json new file mode 100644 index 00000000..004d1e8c --- /dev/null +++ b/step-templates/aws-set-blue-green-target-group.json @@ -0,0 +1,81 @@ +{ + "Id": "4b5f56c1-61f9-4d85-88f8-14dbe8cf8122", + "Name": "AWS - Set Blue-Green Target Group", + "Description": "Sets 100% of traffic to the online target group, and 0% to the offline target group", + "ActionType": "Octopus.AwsRunScript", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "OctopusUseBundledTooling": "False", + "Octopus.Action.Script.ScriptSource": "Inline", + "Octopus.Action.Script.Syntax": "Bash", + "Octopus.Action.Aws.AssumeRole": "False", + "Octopus.Action.AwsAccount.UseInstanceRole": "False", + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}", + "Octopus.Action.Script.ScriptBody": "#!/bin/bash\n\nRULE=${1:-'#{AWSBlueGreen.AWS.RuleArn | Trim}'}\nOFFLINEGROUP=${2:-'#{AWSBlueGreen.AWS.OfflineTargetGroup | Trim}'}\nONLINEGROUP=${3:-'#{AWSBlueGreen.AWS.OnlineTargetGroup | 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.\"\n exit 1\nfi\n\nif [[ -z \"${RULE}\" ]]; then\n echoerror \"Please provide the ARN of the listener rule as the first argument\"\n exit 1\nfi\n\nif [[ -z \"${OFFLINEGROUP}\" ]]; then\n echoerror \"Please provide the ARN of the offline target group as the second argument\"\n exit 1\nfi\n\nif [[ -z \"${ONLINEGROUP}\" ]]; then\n echoerror \"Please provide the ARN of the online target group as the third argument\"\n exit 1\nfi\n\n# https://stackoverflow.com/questions/61074411/modify-aws-alb-traffic-distribution-using-aws-cli\nMODIFYRULE=$(aws elbv2 modify-rule \\\n --rule-arn \"${RULE}\" \\\n --actions \\\n \"[{\n \\\"Type\\\": \\\"forward\\\",\n \\\"Order\\\": 1,\n \\\"ForwardConfig\\\": {\n \\\"TargetGroups\\\": [\n {\\\"TargetGroupArn\\\": \\\"${OFFLINEGROUP}\\\", \\\"Weight\\\": 0 },\n {\\\"TargetGroupArn\\\": \\\"${ONLINEGROUP}\\\", \\\"Weight\\\": 100 }\n ]\n }\n }]\")\n\necho \"Updated listener rules for ${RULE} to set weight to 0 for ${OFFLINEGROUP} and 100 for ${ONLINEGROUP}.\"\n\nwrite_verbose \"${MODIFYRULE}\"", + "Octopus.Action.RunOnServer": "true" + }, + "Parameters": [ + { + "Id": "0835a276-6fae-45e0-863d-021e1ccd4937", + "Name": "AWSBlueGreen.AWS.Account", + "Label": "Account", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "AmazonWebServicesAccount" + } + }, + { + "Id": "0dd99dd4-6676-44e8-b356-c0846f9f40e2", + "Name": "AWSBlueGreen.AWS.Region", + "Label": "Region", + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "2574f380-57b0-437a-8ca3-7a8af9dd1b8b", + "Name": "AWSBlueGreen.AWS.RuleArn", + "Label": "Rule ARN", + "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.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "0483453c-564b-40f8-b80a-b28ba7a26504", + "Name": "AWSBlueGreen.AWS.OfflineTargetGroup", + "Label": "Offline Target Group ARN", + "HelpText": "The ARN of the target group that should receive 0% of the traffic. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "657a1c06-d0b8-4800-b473-d90fa2a63d9e", + "Name": "AWSBlueGreen.AWS.OnlineTargetGroup", + "Label": "Online Target Group ARN", + "HelpText": "The ARN of the target group that should receive 100% of the traffic. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + } + ], + "StepPackageId": "Octopus.AwsRunScript", + "$Meta": { + "ExportedAt": "2025-01-10T03:44:19.550Z", + "OctopusVersion": "2025.1.5319", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "mcasperson", + "Category": "aws" +} diff --git a/step-templates/aws-update-launch-template-ami.json b/step-templates/aws-update-launch-template-ami.json new file mode 100644 index 00000000..7c409d9e --- /dev/null +++ b/step-templates/aws-update-launch-template-ami.json @@ -0,0 +1,80 @@ +{ + "Id": "143400df-19a9-42f5-a6c0-68145489482a", + "Name": "AWS - Update Launch Template AMI", + "Description": "Update the AMI used by a launch template, create a new launch template version, and set the new version as the default.", + "ActionType": "Octopus.AwsRunScript", + "Version": 1, + "CommunityActionTemplateId": null, + "Packages": [], + "GitDependencies": [], + "Properties": { + "OctopusUseBundledTooling": "False", + "Octopus.Action.Script.ScriptSource": "Inline", + "Octopus.Action.Script.Syntax": "Bash", + "Octopus.Action.Aws.AssumeRole": "False", + "Octopus.Action.AwsAccount.UseInstanceRole": "False", + "Octopus.Action.AwsAccount.Variable": "#{AWSBlueGreen.AWS.Account}", + "Octopus.Action.Aws.Region": "#{AWSBlueGreen.AWS.Region}", + "Octopus.Action.Script.ScriptBody": "#!/bin/bash\n\nASG=${1:-'#{AWSBlueGreen.AWS.ASG | Trim}'}\nAMI=${2:-'#{AWSBlueGreen.AWS.AMI | Trim}'}\nVERSIONDESCRIPTION=${3:-'#{AWSBlueGreen.AWS.LaunchTemplateDescription | 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\nif [[ -z \"${ASG}\" ]]; then\n echoerror \"Please provide the name of the Auto Scaling group as the first argument\"\n exit 1\nfi\n\nif [[ -z \"${AMI}\" ]]; then\n echoerror \"Please provide the ID of the new AMI as the second argument\"\n exit 1\nfi\n\nif [[ -z \"${VERSIONDESCRIPTION}\" ]]; then\n echoerror \"Please provide a description for the new launch template version as the third argument\"\n exit 1\nfi\n\nLAUNCHTEMPLATE=$(aws autoscaling describe-auto-scaling-groups \\\n --auto-scaling-group-names \"${ASG}\" \\\n --query 'AutoScalingGroups[0].LaunchTemplate.LaunchTemplateId' \\\n --output text)\n\necho \"Modifying launch template ${LAUNCHTEMPLATE} for Auto Scaling group ${ASG}...\"\n\nNEWVERSION=$(aws ec2 create-launch-template-version \\\n --launch-template-id \"${LAUNCHTEMPLATE}\" \\\n --version-description \"${VERSIONDESCRIPTION}\" \\\n --source-version 1 \\\n --launch-template-data \"ImageId=${AMI}\")\n\nNEWVERSIONNUMBER=$(jq -r '.LaunchTemplateVersion.VersionNumber' <<< \"${NEWVERSION}\")\n\necho \"Set AMI for launch template ${LAUNCHTEMPLATE} to ${AMI}, generating new version ${NEWVERSIONNUMBER}...\"\n\nwrite_verbose \"${NEWVERSION}\"\n\nMODIFYTEMPLATE=$(aws ec2 modify-launch-template \\\n --launch-template-id \"${LAUNCHTEMPLATE}\" \\\n --default-version \"${NEWVERSIONNUMBER}\")\n\necho \"Set default version for launch template ${LAUNCHTEMPLATE} to ${NEWVERSIONNUMBER}...\"\n\nwrite_verbose \"${MODIFYTEMPLATE}\"\n\nUPDATELAUNCHTEMPLATEVERSION=$(aws autoscaling update-auto-scaling-group \\\n --auto-scaling-group-name \"${ASG}\" \\\n --launch-template \"LaunchTemplateId=${LAUNCHTEMPLATE},Version=${NEWVERSIONNUMBER}\")\n\necho \"Updated the ASG launch template version to ${NEWVERSIONNUMBER}...\"\n\nwrite_verbose \"${UPDATELAUNCHTEMPLATEVERSION}\"\n\n" + }, + "Parameters": [ + { + "Id": "11e34c09-311a-49b4-82b7-c33212a07c01", + "Name": "AWSBlueGreen.AWS.Account", + "Label": "Account", + "HelpText": null, + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "AmazonWebServicesAccount" + } + }, + { + "Id": "6a42aaa1-e5f5-4c03-bba7-068fa75eb53f", + "Name": "AWSBlueGreen.AWS.Region", + "Label": "Region", + "HelpText": "The AWS region. See https://aws.amazon.com/about-aws/global-infrastructure/regions_az/ for more information.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "9885f4d6-b8a4-4445-973b-0b6b809e8bd0", + "Name": "AWSBlueGreen.AWS.ASG", + "Label": "ASG Name", + "HelpText": "The name of the auto scaler group to update. See https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-groups.html for more details.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "b89df47e-3d7c-4d88-b3f6-a5b465448978", + "Name": "AWSBlueGreen.AWS.AMI", + "Label": "AMI", + "HelpText": "The AMI image to configure in the launch template. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html for more details.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + }, + { + "Id": "7f7a98b1-067d-47d0-94c8-1a8a3d285c1c", + "Name": "AWSBlueGreen.AWS.LaunchTemplateDescription", + "Label": "Launch Template Version Description", + "HelpText": "The description of the new launch template version.", + "DefaultValue": "", + "DisplaySettings": { + "Octopus.ControlType": "SingleLineText" + } + } + ], + "StepPackageId": "Octopus.AwsRunScript", + "$Meta": { + "ExportedAt": "2025-01-10T03:43:20.697Z", + "OctopusVersion": "2025.1.5319", + "Type": "ActionTemplate" + }, + "LastModifiedBy": "mcasperson", + "Category": "aws" +}