/******************************************************************************* * 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.EKS; using Amazon.EKS.Model; namespace Amazon.PowerShell.Cmdlets.EKS { /// /// Creates an Amazon EKS control plane. /// /// /// /// The Amazon EKS control plane consists of control plane instances that run the Kubernetes /// software, such as etcd and the API server. The control plane runs in /// an account managed by Amazon Web Services, and the Kubernetes API is exposed by the /// Amazon EKS API server endpoint. Each Amazon EKS cluster control plane is single tenant /// and unique. It runs on its own set of Amazon EC2 instances. /// /// The cluster control plane is provisioned across multiple Availability Zones and fronted /// by an Elastic Load Balancing Network Load Balancer. Amazon EKS also provisions elastic /// network interfaces in your VPC subnets to provide connectivity from the control plane /// instances to the nodes (for example, to support kubectl exec, logs, /// and proxy data flows). /// /// Amazon EKS nodes run in your Amazon Web Services account and connect to your cluster's /// control plane over the Kubernetes API server endpoint and a certificate file that /// is created for your cluster. /// /// In most cases, it takes several minutes to create a cluster. After you create an Amazon /// EKS cluster, you must configure your Kubernetes tooling to communicate with the API /// server and launch nodes into your cluster. For more information, see Managing /// Cluster Authentication and Launching /// Amazon EKS nodes in the Amazon EKS User Guide. /// /// [Cmdlet("New", "EKSCluster", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.EKS.Model.Cluster")] [AWSCmdlet("Calls the Amazon Elastic Container Service for Kubernetes CreateCluster API operation.", Operation = new[] {"CreateCluster"}, SelectReturnType = typeof(Amazon.EKS.Model.CreateClusterResponse))] [AWSCmdletOutput("Amazon.EKS.Model.Cluster or Amazon.EKS.Model.CreateClusterResponse", "This cmdlet returns an Amazon.EKS.Model.Cluster object.", "The service call response (type Amazon.EKS.Model.CreateClusterResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewEKSClusterCmdlet : AmazonEKSClientCmdlet, IExecutor { #region Parameter ClientRequestToken /// /// /// Unique, case-sensitive identifier that you provide to ensure the idempotency of the /// request. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ClientRequestToken { get; set; } #endregion #region Parameter Logging_ClusterLogging /// /// /// The cluster control plane logging configuration for your cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public Amazon.EKS.Model.LogSetup[] Logging_ClusterLogging { get; set; } #endregion #region Parameter OutpostConfig_ControlPlaneInstanceType /// /// /// The Amazon EC2 instance type that you want to use for your local Amazon EKS cluster /// on Outposts. Choose an instance type based on the number of nodes that your cluster /// will have. For more information, see Capacity /// considerations in the Amazon EKS User Guide.The instance type that you specify is used for all Kubernetes control plane instances. /// The instance type can't be changed after cluster creation. The control plane is not /// automatically scaled by Amazon EKS. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String OutpostConfig_ControlPlaneInstanceType { get; set; } #endregion #region Parameter EncryptionConfig /// /// /// The encryption configuration for the cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public Amazon.EKS.Model.EncryptionConfig[] EncryptionConfig { get; set; } #endregion #region Parameter ControlPlanePlacement_GroupName /// /// /// The name of the placement group for the Kubernetes control plane instances. This setting /// can't be changed after cluster creation. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("OutpostConfig_ControlPlanePlacement_GroupName")] public System.String ControlPlanePlacement_GroupName { get; set; } #endregion #region Parameter KubernetesNetworkConfig_IpFamily /// /// /// Specify which IP family is used to assign Kubernetes pod and service IP addresses. /// If you don't specify a value, ipv4 is used by default. You can only specify /// an IP family when you create a cluster and can't change this value once the cluster /// is created. If you specify ipv6, the VPC and subnets that you specify /// for cluster creation must have both IPv4 and IPv6 CIDR blocks /// assigned to them. You can't specify ipv6 for clusters in China Regions.You can only specify ipv6 for 1.21 and later clusters that /// use version 1.10.1 or later of the Amazon VPC CNI add-on. If you specify /// ipv6, then ensure that your VPC meets the requirements listed in the /// considerations listed in Assigning /// IPv6 addresses to pods and services in the Amazon EKS User Guide. Kubernetes assigns /// services IPv6 addresses from the unique local address range (fc00::/7). /// You can't specify a custom IPv6 CIDR block. Pod addresses are assigned /// from the subnet's IPv6 CIDR. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.EKS.IpFamily")] public Amazon.EKS.IpFamily KubernetesNetworkConfig_IpFamily { get; set; } #endregion #region Parameter Name /// /// /// The unique name to give to your cluster. /// /// #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 Name { get; set; } #endregion #region Parameter OutpostConfig_OutpostArn /// /// /// The ARN of the Outpost that you want to use for your local Amazon EKS cluster on Outposts. /// Only a single Outpost ARN is supported. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("OutpostConfig_OutpostArns")] public System.String[] OutpostConfig_OutpostArn { get; set; } #endregion #region Parameter ResourcesVpcConfig /// /// /// The VPC configuration that's used by the cluster control plane. Amazon EKS VPC resources /// have specific requirements to work properly with Kubernetes. For more information, /// see Cluster /// VPC Considerations and Cluster /// Security Group Considerations in the Amazon EKS User Guide. You must specify /// at least two subnets. You can specify up to five security groups. However, we recommend /// that you use a dedicated security group for your cluster control plane. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public Amazon.EKS.Model.VpcConfigRequest ResourcesVpcConfig { get; set; } #endregion #region Parameter RoleArn /// /// /// The Amazon Resource Name (ARN) of the IAM role that provides permissions for the Kubernetes /// control plane to make calls to Amazon Web Services API operations on your behalf. /// For more information, see Amazon /// EKS Service IAM Role in the Amazon EKS User Guide. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String RoleArn { get; set; } #endregion #region Parameter KubernetesNetworkConfig_ServiceIpv4Cidr /// /// /// Don't specify a value if you select ipv6 for ipFamily. The CIDR /// block to assign Kubernetes service IP addresses from. If you don't specify a block, /// Kubernetes assigns addresses from either the 10.100.0.0/16 or 172.20.0.0/16 /// CIDR blocks. We recommend that you specify a block that does not overlap with resources /// in other networks that are peered or connected to your VPC. The block must meet the /// following requirements:You can only specify a custom CIDR block when you create a cluster and can't change /// this value once the cluster is created. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KubernetesNetworkConfig_ServiceIpv4Cidr { get; set; } #endregion #region Parameter Tag /// /// /// The metadata to apply to the cluster to assist with categorization and organization. /// Each tag consists of a key and an optional value. You define both. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public System.Collections.Hashtable Tag { get; set; } #endregion #region Parameter Version /// /// /// The desired Kubernetes version for your cluster. If you don't specify a value here, /// the default version available in Amazon EKS is used.The default version might not be the latest version available. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Version { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'Cluster'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.EKS.Model.CreateClusterResponse). /// Specifying the name of a property of type Amazon.EKS.Model.CreateClusterResponse will result in that property being returned. /// 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; } = "Cluster"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the Name parameter. /// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' 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.Name), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-EKSCluster (CreateCluster)")) { 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.Name; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ClientRequestToken = this.ClientRequestToken; if (this.EncryptionConfig != null) { context.EncryptionConfig = new List(this.EncryptionConfig); } context.KubernetesNetworkConfig_IpFamily = this.KubernetesNetworkConfig_IpFamily; context.KubernetesNetworkConfig_ServiceIpv4Cidr = this.KubernetesNetworkConfig_ServiceIpv4Cidr; if (this.Logging_ClusterLogging != null) { context.Logging_ClusterLogging = new List(this.Logging_ClusterLogging); } context.Name = this.Name; #if MODULAR if (this.Name == null && ParameterWasBound(nameof(this.Name))) { WriteWarning("You are passing $null as a value for parameter Name 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.OutpostConfig_ControlPlaneInstanceType = this.OutpostConfig_ControlPlaneInstanceType; context.ControlPlanePlacement_GroupName = this.ControlPlanePlacement_GroupName; if (this.OutpostConfig_OutpostArn != null) { context.OutpostConfig_OutpostArn = new List(this.OutpostConfig_OutpostArn); } context.ResourcesVpcConfig = this.ResourcesVpcConfig; #if MODULAR if (this.ResourcesVpcConfig == null && ParameterWasBound(nameof(this.ResourcesVpcConfig))) { WriteWarning("You are passing $null as a value for parameter ResourcesVpcConfig 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.RoleArn = this.RoleArn; #if MODULAR if (this.RoleArn == null && ParameterWasBound(nameof(this.RoleArn))) { WriteWarning("You are passing $null as a value for parameter RoleArn 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.Tag != null) { context.Tag = new Dictionary(StringComparer.Ordinal); foreach (var hashKey in this.Tag.Keys) { context.Tag.Add((String)hashKey, (String)(this.Tag[hashKey])); } } context.Version = this.Version; // 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.EKS.Model.CreateClusterRequest(); if (cmdletContext.ClientRequestToken != null) { request.ClientRequestToken = cmdletContext.ClientRequestToken; } if (cmdletContext.EncryptionConfig != null) { request.EncryptionConfig = cmdletContext.EncryptionConfig; } // populate KubernetesNetworkConfig var requestKubernetesNetworkConfigIsNull = true; request.KubernetesNetworkConfig = new Amazon.EKS.Model.KubernetesNetworkConfigRequest(); Amazon.EKS.IpFamily requestKubernetesNetworkConfig_kubernetesNetworkConfig_IpFamily = null; if (cmdletContext.KubernetesNetworkConfig_IpFamily != null) { requestKubernetesNetworkConfig_kubernetesNetworkConfig_IpFamily = cmdletContext.KubernetesNetworkConfig_IpFamily; } if (requestKubernetesNetworkConfig_kubernetesNetworkConfig_IpFamily != null) { request.KubernetesNetworkConfig.IpFamily = requestKubernetesNetworkConfig_kubernetesNetworkConfig_IpFamily; requestKubernetesNetworkConfigIsNull = false; } System.String requestKubernetesNetworkConfig_kubernetesNetworkConfig_ServiceIpv4Cidr = null; if (cmdletContext.KubernetesNetworkConfig_ServiceIpv4Cidr != null) { requestKubernetesNetworkConfig_kubernetesNetworkConfig_ServiceIpv4Cidr = cmdletContext.KubernetesNetworkConfig_ServiceIpv4Cidr; } if (requestKubernetesNetworkConfig_kubernetesNetworkConfig_ServiceIpv4Cidr != null) { request.KubernetesNetworkConfig.ServiceIpv4Cidr = requestKubernetesNetworkConfig_kubernetesNetworkConfig_ServiceIpv4Cidr; requestKubernetesNetworkConfigIsNull = false; } // determine if request.KubernetesNetworkConfig should be set to null if (requestKubernetesNetworkConfigIsNull) { request.KubernetesNetworkConfig = null; } // populate Logging var requestLoggingIsNull = true; request.Logging = new Amazon.EKS.Model.Logging(); List requestLogging_logging_ClusterLogging = null; if (cmdletContext.Logging_ClusterLogging != null) { requestLogging_logging_ClusterLogging = cmdletContext.Logging_ClusterLogging; } if (requestLogging_logging_ClusterLogging != null) { request.Logging.ClusterLogging = requestLogging_logging_ClusterLogging; requestLoggingIsNull = false; } // determine if request.Logging should be set to null if (requestLoggingIsNull) { request.Logging = null; } if (cmdletContext.Name != null) { request.Name = cmdletContext.Name; } // populate OutpostConfig var requestOutpostConfigIsNull = true; request.OutpostConfig = new Amazon.EKS.Model.OutpostConfigRequest(); System.String requestOutpostConfig_outpostConfig_ControlPlaneInstanceType = null; if (cmdletContext.OutpostConfig_ControlPlaneInstanceType != null) { requestOutpostConfig_outpostConfig_ControlPlaneInstanceType = cmdletContext.OutpostConfig_ControlPlaneInstanceType; } if (requestOutpostConfig_outpostConfig_ControlPlaneInstanceType != null) { request.OutpostConfig.ControlPlaneInstanceType = requestOutpostConfig_outpostConfig_ControlPlaneInstanceType; requestOutpostConfigIsNull = false; } List requestOutpostConfig_outpostConfig_OutpostArn = null; if (cmdletContext.OutpostConfig_OutpostArn != null) { requestOutpostConfig_outpostConfig_OutpostArn = cmdletContext.OutpostConfig_OutpostArn; } if (requestOutpostConfig_outpostConfig_OutpostArn != null) { request.OutpostConfig.OutpostArns = requestOutpostConfig_outpostConfig_OutpostArn; requestOutpostConfigIsNull = false; } Amazon.EKS.Model.ControlPlanePlacementRequest requestOutpostConfig_outpostConfig_ControlPlanePlacement = null; // populate ControlPlanePlacement var requestOutpostConfig_outpostConfig_ControlPlanePlacementIsNull = true; requestOutpostConfig_outpostConfig_ControlPlanePlacement = new Amazon.EKS.Model.ControlPlanePlacementRequest(); System.String requestOutpostConfig_outpostConfig_ControlPlanePlacement_controlPlanePlacement_GroupName = null; if (cmdletContext.ControlPlanePlacement_GroupName != null) { requestOutpostConfig_outpostConfig_ControlPlanePlacement_controlPlanePlacement_GroupName = cmdletContext.ControlPlanePlacement_GroupName; } if (requestOutpostConfig_outpostConfig_ControlPlanePlacement_controlPlanePlacement_GroupName != null) { requestOutpostConfig_outpostConfig_ControlPlanePlacement.GroupName = requestOutpostConfig_outpostConfig_ControlPlanePlacement_controlPlanePlacement_GroupName; requestOutpostConfig_outpostConfig_ControlPlanePlacementIsNull = false; } // determine if requestOutpostConfig_outpostConfig_ControlPlanePlacement should be set to null if (requestOutpostConfig_outpostConfig_ControlPlanePlacementIsNull) { requestOutpostConfig_outpostConfig_ControlPlanePlacement = null; } if (requestOutpostConfig_outpostConfig_ControlPlanePlacement != null) { request.OutpostConfig.ControlPlanePlacement = requestOutpostConfig_outpostConfig_ControlPlanePlacement; requestOutpostConfigIsNull = false; } // determine if request.OutpostConfig should be set to null if (requestOutpostConfigIsNull) { request.OutpostConfig = null; } if (cmdletContext.ResourcesVpcConfig != null) { request.ResourcesVpcConfig = cmdletContext.ResourcesVpcConfig; } if (cmdletContext.RoleArn != null) { request.RoleArn = cmdletContext.RoleArn; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.Version != null) { request.Version = cmdletContext.Version; } 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.EKS.Model.CreateClusterResponse CallAWSServiceOperation(IAmazonEKS client, Amazon.EKS.Model.CreateClusterRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Container Service for Kubernetes", "CreateCluster"); try { #if DESKTOP return client.CreateCluster(request); #elif CORECLR return client.CreateClusterAsync(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 ClientRequestToken { get; set; } public List EncryptionConfig { get; set; } public Amazon.EKS.IpFamily KubernetesNetworkConfig_IpFamily { get; set; } public System.String KubernetesNetworkConfig_ServiceIpv4Cidr { get; set; } public List Logging_ClusterLogging { get; set; } public System.String Name { get; set; } public System.String OutpostConfig_ControlPlaneInstanceType { get; set; } public System.String ControlPlanePlacement_GroupName { get; set; } public List OutpostConfig_OutpostArn { get; set; } public Amazon.EKS.Model.VpcConfigRequest ResourcesVpcConfig { get; set; } public System.String RoleArn { get; set; } public Dictionary Tag { get; set; } public System.String Version { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.Cluster; } } }