/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.AutoScaling;
using Amazon.AutoScaling.Model;
namespace Amazon.PowerShell.Cmdlets.AS
{
///
/// We strongly recommend using a launch template when calling this operation to ensure
/// full functionality for Amazon EC2 Auto Scaling and Amazon EC2.
/// Creates an Auto Scaling group with the specified name and attributes.
///
/// If you exceed your maximum limit of Auto Scaling groups, the call fails. To query
/// this limit, call the DescribeAccountLimits API. For information about updating
/// this limit, see Quotas
/// for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.
///
/// For introductory exercises for creating an Auto Scaling group, see Getting
/// started with Amazon EC2 Auto Scaling and Tutorial:
/// Set up a scaled and load-balanced application in the Amazon EC2 Auto Scaling
/// User Guide. For more information, see Auto
/// Scaling groups in the Amazon EC2 Auto Scaling User Guide.
///
/// Every Auto Scaling group has three size properties (DesiredCapacity
,
/// MaxSize
, and MinSize
). Usually, you set these sizes based
/// on a specific number of instances. However, if you configure a mixed instances policy
/// that defines weights for the instance types, you must specify these sizes with the
/// same units that you use for weighting instances.
///
///
[Cmdlet("New", "ASAutoScalingGroup", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("None")]
[AWSCmdlet("Calls the AWS Auto Scaling CreateAutoScalingGroup API operation.", Operation = new[] {"CreateAutoScalingGroup"}, SelectReturnType = typeof(Amazon.AutoScaling.Model.CreateAutoScalingGroupResponse))]
[AWSCmdletOutput("None or Amazon.AutoScaling.Model.CreateAutoScalingGroupResponse",
"This cmdlet does not generate any output." +
"The service response (type Amazon.AutoScaling.Model.CreateAutoScalingGroupResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewASAutoScalingGroupCmdlet : AmazonAutoScalingClientCmdlet, IExecutor
{
#region Parameter AutoScalingGroupName
///
///
/// The name of the Auto Scaling group. This name must be unique per Region per account.The name can contain any ASCII character 33 to 126 including most punctuation characters,
/// digits, and upper and lowercased letters.You cannot use a colon (:) in the name.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String AutoScalingGroupName { get; set; }
#endregion
#region Parameter AvailabilityZone
///
///
/// A list of Availability Zones where instances in the Auto Scaling group can be created.
/// Used for launching into the default VPC subnet in each Availability Zone when not
/// using the VPCZoneIdentifier
property, or for attaching a network interface
/// when an existing network interface ID is specified in a launch template.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("AvailabilityZones")]
public System.String[] AvailabilityZone { get; set; }
#endregion
#region Parameter CapacityRebalance
///
///
/// Indicates whether Capacity Rebalancing is enabled. Otherwise, Capacity Rebalancing
/// is disabled. When you turn on Capacity Rebalancing, Amazon EC2 Auto Scaling attempts
/// to launch a Spot Instance whenever Amazon EC2 notifies that a Spot Instance is at
/// an elevated risk of interruption. After launching a new instance, it then terminates
/// an old instance. For more information, see Use
/// Capacity Rebalancing to handle Amazon EC2 Spot Interruptions in the in the Amazon
/// EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? CapacityRebalance { get; set; }
#endregion
#region Parameter Context
///
///
/// Reserved.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Context { get; set; }
#endregion
#region Parameter DefaultCooldown
///
///
/// Only needed if you use simple scaling policies.The amount of time, in seconds, between one scaling activity ending and another one
/// starting due to simple scaling policies. For more information, see Scaling
/// cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.Default: 300
seconds
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? DefaultCooldown { get; set; }
#endregion
#region Parameter DefaultInstanceWarmup
///
///
/// The amount of time, in seconds, until a new instance is considered to have finished
/// initializing and resource consumption to become stable after it enters the InService
/// state. During an instance refresh, Amazon EC2 Auto Scaling waits for the warm-up period after
/// it replaces an instance before it moves on to replacing the next instance. Amazon
/// EC2 Auto Scaling also waits for the warm-up period before aggregating the metrics
/// for new instances with existing instances in the Amazon CloudWatch metrics that are
/// used for scaling, resulting in more reliable usage data. For more information, see
/// Set
/// the default instance warmup for an Auto Scaling group in the Amazon EC2 Auto
/// Scaling User Guide.To manage various warm-up settings at the group level, we recommend that you set the
/// default instance warmup, even if it is set to 0 seconds. To remove a value
/// that you previously set, include the property but specify -1
for the
/// value. However, we strongly recommend keeping the default instance warmup enabled
/// by specifying a value of 0
or other nominal value.Default: None
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? DefaultInstanceWarmup { get; set; }
#endregion
#region Parameter DesiredCapacity
///
///
/// The desired capacity is the initial capacity of the Auto Scaling group at the time
/// of its creation and the capacity it attempts to maintain. It can scale beyond this
/// capacity if you configure auto scaling. This number must be greater than or equal
/// to the minimum size of the group and less than or equal to the maximum size of the
/// group. If you do not specify a desired capacity, the default is the minimum size of
/// the group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? DesiredCapacity { get; set; }
#endregion
#region Parameter DesiredCapacityType
///
///
/// The unit of measurement for the value specified for desired capacity. Amazon EC2 Auto
/// Scaling supports DesiredCapacityType
for attribute-based instance type
/// selection only. For more information, see Creating
/// an Auto Scaling group using attribute-based instance type selection in the Amazon
/// EC2 Auto Scaling User Guide.By default, Amazon EC2 Auto Scaling specifies units
, which translates
/// into number of instances.Valid values: units
| vcpu
| memory-mib
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String DesiredCapacityType { get; set; }
#endregion
#region Parameter HealthCheckGracePeriod
///
///
/// The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking
/// the health status of an EC2 instance that has come into service and marking it unhealthy
/// due to a failed health check. This is useful if your instances do not immediately
/// pass their health checks after they enter the InService
state. For more
/// information, see Set
/// the health check grace period for an Auto Scaling group in the Amazon EC2 Auto
/// Scaling User Guide.Default: 0
seconds
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? HealthCheckGracePeriod { get; set; }
#endregion
#region Parameter HealthCheckType
///
///
/// A comma-separated value string of one or more health check types.The valid values are EC2
, ELB
, and VPC_LATTICE
.
/// EC2
is the default health check and cannot be disabled. For more information,
/// see Health
/// checks for Auto Scaling instances in the Amazon EC2 Auto Scaling User Guide.Only specify EC2
if you must clear a value that was previously set.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String HealthCheckType { get; set; }
#endregion
#region Parameter InstanceId
///
///
/// The ID of the instance used to base the launch configuration on. If specified, Amazon
/// EC2 Auto Scaling uses the configuration values from the specified instance to create
/// a new launch configuration. To get the instance ID, use the Amazon EC2 DescribeInstances
/// API operation. For more information, see Creating
/// an Auto Scaling group using an EC2 instance in the Amazon EC2 Auto Scaling
/// User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String InstanceId { get; set; }
#endregion
#region Parameter LaunchConfigurationName
///
///
/// The name of the launch configuration to use to launch instances. Conditional: You must specify either a launch template (LaunchTemplate
/// or MixedInstancesPolicy
) or a launch configuration (LaunchConfigurationName
/// or InstanceId
).
///
///
[System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)]
public System.String LaunchConfigurationName { get; set; }
#endregion
#region Parameter LaunchTemplate_LaunchTemplateId
///
///
/// The ID of the launch template. To get the template ID, use the Amazon EC2 DescribeLaunchTemplates
/// API operation. New launch templates can be created using the Amazon EC2 CreateLaunchTemplate
/// API. Conditional: You must specify either a LaunchTemplateId
or a LaunchTemplateName
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String LaunchTemplate_LaunchTemplateId { get; set; }
#endregion
#region Parameter LaunchTemplate_LaunchTemplateName
///
///
/// The name of the launch template. To get the template name, use the Amazon EC2 DescribeLaunchTemplates
/// API operation. New launch templates can be created using the Amazon EC2 CreateLaunchTemplate
/// API. Conditional: You must specify either a LaunchTemplateId
or a LaunchTemplateName
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String LaunchTemplate_LaunchTemplateName { get; set; }
#endregion
#region Parameter LifecycleHookSpecificationList
///
///
/// One or more lifecycle hooks to add to the Auto Scaling group before instances are
/// launched.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.AutoScaling.Model.LifecycleHookSpecification[] LifecycleHookSpecificationList { get; set; }
#endregion
#region Parameter LoadBalancerName
///
///
/// A list of Classic Load Balancers associated with this Auto Scaling group. For Application
/// Load Balancers, Network Load Balancers, and Gateway Load Balancers, specify the TargetGroupARNs
/// property instead.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LoadBalancerNames")]
public System.String[] LoadBalancerName { get; set; }
#endregion
#region Parameter MaxInstanceLifetime
///
///
/// The maximum amount of time, in seconds, that an instance can be in service. The default
/// is null. If specified, the value must be either 0 or a number equal to or greater
/// than 86,400 seconds (1 day). For more information, see Replacing
/// Auto Scaling instances based on maximum instance lifetime in the Amazon EC2
/// Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? MaxInstanceLifetime { get; set; }
#endregion
#region Parameter MaxSize
///
///
/// The maximum size of the group.With a mixed instances policy that uses instance weighting, Amazon EC2 Auto Scaling
/// may need to go above MaxSize
to meet your capacity requirements. In this
/// event, Amazon EC2 Auto Scaling will never go above MaxSize
by more than
/// your largest instance weight (weights that define how many units each instance contributes
/// to the desired capacity of the group).
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 3, ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(Position = 3, ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.Int32? MaxSize { get; set; }
#endregion
#region Parameter MinSize
///
///
/// The minimum size of the group.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.Int32? MinSize { get; set; }
#endregion
#region Parameter MixedInstancesPolicy
///
///
/// The mixed instances policy. For more information, see Auto
/// Scaling groups with multiple instance types and purchase options in the Amazon
/// EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.AutoScaling.Model.MixedInstancesPolicy MixedInstancesPolicy { get; set; }
#endregion
#region Parameter NewInstancesProtectedFromScaleIn
///
///
/// Indicates whether newly launched instances are protected from termination by Amazon
/// EC2 Auto Scaling when scaling in. For more information about preventing instances
/// from terminating on scale in, see Using
/// instance scale-in protection in the Amazon EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? NewInstancesProtectedFromScaleIn { get; set; }
#endregion
#region Parameter PlacementGroup
///
///
/// The name of the placement group into which to launch your instances. For more information,
/// see Placement
/// groups in the Amazon EC2 User Guide for Linux Instances.A cluster placement group is a logical grouping of instances within a single
/// Availability Zone. You cannot specify multiple Availability Zones and a cluster placement
/// group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PlacementGroup { get; set; }
#endregion
#region Parameter ServiceLinkedRoleARN
///
///
/// The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group
/// uses to call other Amazon Web Services service on your behalf. By default, Amazon
/// EC2 Auto Scaling uses a service-linked role named AWSServiceRoleForAutoScaling
,
/// which it creates if it does not exist. For more information, see Service-linked
/// roles in the Amazon EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ServiceLinkedRoleARN { get; set; }
#endregion
#region Parameter Tag
///
///
/// One or more tags. You can tag your Auto Scaling group and propagate the tags to the
/// Amazon EC2 instances it launches. Tags are not propagated to Amazon EBS volumes. To
/// add tags to Amazon EBS volumes, specify the tags in a launch template but use caution.
/// If the launch template specifies an instance tag with a key that is also specified
/// for the Auto Scaling group, Amazon EC2 Auto Scaling overrides the value of that instance
/// tag with the value specified by the Auto Scaling group. For more information, see
/// Tag
/// Auto Scaling groups and instances in the Amazon EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.AutoScaling.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter TargetGroupARNs
///
///
/// The Amazon Resource Names (ARN) of the Elastic Load Balancing target groups to associate
/// with the Auto Scaling group. Instances are registered as targets with the target groups.
/// The target groups receive incoming traffic and route requests to one or more registered
/// targets. For more information, see Use
/// Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling
/// group in the Amazon EC2 Auto Scaling User Guide.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String[] TargetGroupARNs { get; set; }
#endregion
#region Parameter TerminationPolicy
///
///
/// A policy or a list of policies that are used to select the instance to terminate.
/// These policies are executed in the order that you list them. For more information,
/// see Work
/// with Amazon EC2 Auto Scaling termination policies in the Amazon EC2 Auto Scaling
/// User Guide.Valid values: Default
| AllocationStrategy
| ClosestToNextInstanceHour
/// | NewestInstance
| OldestInstance
| OldestLaunchConfiguration
/// | OldestLaunchTemplate
| arn:aws:lambda:region:account-id:function:my-function:my-alias
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TerminationPolicies")]
public System.String[] TerminationPolicy { get; set; }
#endregion
#region Parameter TrafficSource
///
///
/// The list of traffic sources to attach to this Auto Scaling group. You can use any
/// of the following as traffic sources for an Auto Scaling group: Classic Load Balancer,
/// Application Load Balancer, Gateway Load Balancer, Network Load Balancer, and VPC Lattice.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TrafficSources")]
public Amazon.AutoScaling.Model.TrafficSourceIdentifier[] TrafficSource { get; set; }
#endregion
#region Parameter LaunchTemplate_Version
///
///
/// The version number, $Latest
, or $Default
. To get the version
/// number, use the Amazon EC2 DescribeLaunchTemplateVersions
/// API operation. New launch template versions can be created using the Amazon EC2 CreateLaunchTemplateVersion
/// API. If the value is $Latest
, Amazon EC2 Auto Scaling selects the latest
/// version of the launch template when launching instances. If the value is $Default
,
/// Amazon EC2 Auto Scaling selects the default version of the launch template when launching
/// instances. The default value is $Default
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String LaunchTemplate_Version { get; set; }
#endregion
#region Parameter VPCZoneIdentifier
///
///
/// A comma-separated list of subnet IDs for a virtual private cloud (VPC) where instances
/// in the Auto Scaling group can be created. If you specify VPCZoneIdentifier
/// with AvailabilityZones
, the subnets that you specify must reside in those
/// Availability Zones.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String VPCZoneIdentifier { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The cmdlet doesn't have a return value by default.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.AutoScaling.Model.CreateAutoScalingGroupResponse).
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the AutoScalingGroupName parameter.
/// The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^AutoScalingGroupName' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.AutoScalingGroupName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-ASAutoScalingGroup (CreateAutoScalingGroup)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.AutoScalingGroupName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AutoScalingGroupName = this.AutoScalingGroupName;
#if MODULAR
if (this.AutoScalingGroupName == null && ParameterWasBound(nameof(this.AutoScalingGroupName)))
{
WriteWarning("You are passing $null as a value for parameter AutoScalingGroupName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
if (this.AvailabilityZone != null)
{
context.AvailabilityZone = new List(this.AvailabilityZone);
}
context.CapacityRebalance = this.CapacityRebalance;
context.Context = this.Context;
context.DefaultCooldown = this.DefaultCooldown;
context.DefaultInstanceWarmup = this.DefaultInstanceWarmup;
context.DesiredCapacity = this.DesiredCapacity;
context.DesiredCapacityType = this.DesiredCapacityType;
context.HealthCheckGracePeriod = this.HealthCheckGracePeriod;
context.HealthCheckType = this.HealthCheckType;
context.InstanceId = this.InstanceId;
context.LaunchConfigurationName = this.LaunchConfigurationName;
context.LaunchTemplate_LaunchTemplateId = this.LaunchTemplate_LaunchTemplateId;
context.LaunchTemplate_LaunchTemplateName = this.LaunchTemplate_LaunchTemplateName;
context.LaunchTemplate_Version = this.LaunchTemplate_Version;
if (this.LifecycleHookSpecificationList != null)
{
context.LifecycleHookSpecificationList = new List(this.LifecycleHookSpecificationList);
}
if (this.LoadBalancerName != null)
{
context.LoadBalancerName = new List(this.LoadBalancerName);
}
context.MaxInstanceLifetime = this.MaxInstanceLifetime;
context.MaxSize = this.MaxSize;
#if MODULAR
if (this.MaxSize == null && ParameterWasBound(nameof(this.MaxSize)))
{
WriteWarning("You are passing $null as a value for parameter MaxSize which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.MinSize = this.MinSize;
#if MODULAR
if (this.MinSize == null && ParameterWasBound(nameof(this.MinSize)))
{
WriteWarning("You are passing $null as a value for parameter MinSize which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.MixedInstancesPolicy = this.MixedInstancesPolicy;
context.NewInstancesProtectedFromScaleIn = this.NewInstancesProtectedFromScaleIn;
context.PlacementGroup = this.PlacementGroup;
context.ServiceLinkedRoleARN = this.ServiceLinkedRoleARN;
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
if (this.TargetGroupARNs != null)
{
context.TargetGroupARNs = new List(this.TargetGroupARNs);
}
if (this.TerminationPolicy != null)
{
context.TerminationPolicy = new List(this.TerminationPolicy);
}
if (this.TrafficSource != null)
{
context.TrafficSource = new List(this.TrafficSource);
}
context.VPCZoneIdentifier = this.VPCZoneIdentifier;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.AutoScaling.Model.CreateAutoScalingGroupRequest();
if (cmdletContext.AutoScalingGroupName != null)
{
request.AutoScalingGroupName = cmdletContext.AutoScalingGroupName;
}
if (cmdletContext.AvailabilityZone != null)
{
request.AvailabilityZones = cmdletContext.AvailabilityZone;
}
if (cmdletContext.CapacityRebalance != null)
{
request.CapacityRebalance = cmdletContext.CapacityRebalance.Value;
}
if (cmdletContext.Context != null)
{
request.Context = cmdletContext.Context;
}
if (cmdletContext.DefaultCooldown != null)
{
request.DefaultCooldown = cmdletContext.DefaultCooldown.Value;
}
if (cmdletContext.DefaultInstanceWarmup != null)
{
request.DefaultInstanceWarmup = cmdletContext.DefaultInstanceWarmup.Value;
}
if (cmdletContext.DesiredCapacity != null)
{
request.DesiredCapacity = cmdletContext.DesiredCapacity.Value;
}
if (cmdletContext.DesiredCapacityType != null)
{
request.DesiredCapacityType = cmdletContext.DesiredCapacityType;
}
if (cmdletContext.HealthCheckGracePeriod != null)
{
request.HealthCheckGracePeriod = cmdletContext.HealthCheckGracePeriod.Value;
}
if (cmdletContext.HealthCheckType != null)
{
request.HealthCheckType = cmdletContext.HealthCheckType;
}
if (cmdletContext.InstanceId != null)
{
request.InstanceId = cmdletContext.InstanceId;
}
if (cmdletContext.LaunchConfigurationName != null)
{
request.LaunchConfigurationName = cmdletContext.LaunchConfigurationName;
}
// populate LaunchTemplate
var requestLaunchTemplateIsNull = true;
request.LaunchTemplate = new Amazon.AutoScaling.Model.LaunchTemplateSpecification();
System.String requestLaunchTemplate_launchTemplate_LaunchTemplateId = null;
if (cmdletContext.LaunchTemplate_LaunchTemplateId != null)
{
requestLaunchTemplate_launchTemplate_LaunchTemplateId = cmdletContext.LaunchTemplate_LaunchTemplateId;
}
if (requestLaunchTemplate_launchTemplate_LaunchTemplateId != null)
{
request.LaunchTemplate.LaunchTemplateId = requestLaunchTemplate_launchTemplate_LaunchTemplateId;
requestLaunchTemplateIsNull = false;
}
System.String requestLaunchTemplate_launchTemplate_LaunchTemplateName = null;
if (cmdletContext.LaunchTemplate_LaunchTemplateName != null)
{
requestLaunchTemplate_launchTemplate_LaunchTemplateName = cmdletContext.LaunchTemplate_LaunchTemplateName;
}
if (requestLaunchTemplate_launchTemplate_LaunchTemplateName != null)
{
request.LaunchTemplate.LaunchTemplateName = requestLaunchTemplate_launchTemplate_LaunchTemplateName;
requestLaunchTemplateIsNull = false;
}
System.String requestLaunchTemplate_launchTemplate_Version = null;
if (cmdletContext.LaunchTemplate_Version != null)
{
requestLaunchTemplate_launchTemplate_Version = cmdletContext.LaunchTemplate_Version;
}
if (requestLaunchTemplate_launchTemplate_Version != null)
{
request.LaunchTemplate.Version = requestLaunchTemplate_launchTemplate_Version;
requestLaunchTemplateIsNull = false;
}
// determine if request.LaunchTemplate should be set to null
if (requestLaunchTemplateIsNull)
{
request.LaunchTemplate = null;
}
if (cmdletContext.LifecycleHookSpecificationList != null)
{
request.LifecycleHookSpecificationList = cmdletContext.LifecycleHookSpecificationList;
}
if (cmdletContext.LoadBalancerName != null)
{
request.LoadBalancerNames = cmdletContext.LoadBalancerName;
}
if (cmdletContext.MaxInstanceLifetime != null)
{
request.MaxInstanceLifetime = cmdletContext.MaxInstanceLifetime.Value;
}
if (cmdletContext.MaxSize != null)
{
request.MaxSize = cmdletContext.MaxSize.Value;
}
if (cmdletContext.MinSize != null)
{
request.MinSize = cmdletContext.MinSize.Value;
}
if (cmdletContext.MixedInstancesPolicy != null)
{
request.MixedInstancesPolicy = cmdletContext.MixedInstancesPolicy;
}
if (cmdletContext.NewInstancesProtectedFromScaleIn != null)
{
request.NewInstancesProtectedFromScaleIn = cmdletContext.NewInstancesProtectedFromScaleIn.Value;
}
if (cmdletContext.PlacementGroup != null)
{
request.PlacementGroup = cmdletContext.PlacementGroup;
}
if (cmdletContext.ServiceLinkedRoleARN != null)
{
request.ServiceLinkedRoleARN = cmdletContext.ServiceLinkedRoleARN;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.TargetGroupARNs != null)
{
request.TargetGroupARNs = cmdletContext.TargetGroupARNs;
}
if (cmdletContext.TerminationPolicy != null)
{
request.TerminationPolicies = cmdletContext.TerminationPolicy;
}
if (cmdletContext.TrafficSource != null)
{
request.TrafficSources = cmdletContext.TrafficSource;
}
if (cmdletContext.VPCZoneIdentifier != null)
{
request.VPCZoneIdentifier = cmdletContext.VPCZoneIdentifier;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.AutoScaling.Model.CreateAutoScalingGroupResponse CallAWSServiceOperation(IAmazonAutoScaling client, Amazon.AutoScaling.Model.CreateAutoScalingGroupRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Auto Scaling", "CreateAutoScalingGroup");
try
{
#if DESKTOP
return client.CreateAutoScalingGroup(request);
#elif CORECLR
return client.CreateAutoScalingGroupAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String AutoScalingGroupName { get; set; }
public List AvailabilityZone { get; set; }
public System.Boolean? CapacityRebalance { get; set; }
public System.String Context { get; set; }
public System.Int32? DefaultCooldown { get; set; }
public System.Int32? DefaultInstanceWarmup { get; set; }
public System.Int32? DesiredCapacity { get; set; }
public System.String DesiredCapacityType { get; set; }
public System.Int32? HealthCheckGracePeriod { get; set; }
public System.String HealthCheckType { get; set; }
public System.String InstanceId { get; set; }
public System.String LaunchConfigurationName { get; set; }
public System.String LaunchTemplate_LaunchTemplateId { get; set; }
public System.String LaunchTemplate_LaunchTemplateName { get; set; }
public System.String LaunchTemplate_Version { get; set; }
public List LifecycleHookSpecificationList { get; set; }
public List LoadBalancerName { get; set; }
public System.Int32? MaxInstanceLifetime { get; set; }
public System.Int32? MaxSize { get; set; }
public System.Int32? MinSize { get; set; }
public Amazon.AutoScaling.Model.MixedInstancesPolicy MixedInstancesPolicy { get; set; }
public System.Boolean? NewInstancesProtectedFromScaleIn { get; set; }
public System.String PlacementGroup { get; set; }
public System.String ServiceLinkedRoleARN { get; set; }
public List Tag { get; set; }
public List TargetGroupARNs { get; set; }
public List TerminationPolicy { get; set; }
public List TrafficSource { get; set; }
public System.String VPCZoneIdentifier { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => null;
}
}
}