/*******************************************************************************
* 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.EC2;
using Amazon.EC2.Model;
namespace Amazon.PowerShell.Cmdlets.EC2
{
///
/// Creates a VPC endpoint. A VPC endpoint provides a private connection between the specified
/// VPC and the specified endpoint service. You can use an endpoint service provided by
/// Amazon Web Services, an Amazon Web Services Marketplace Partner, or another Amazon
/// Web Services account. For more information, see the Amazon
/// Web Services PrivateLink User Guide.
///
[Cmdlet("New", "EC2VpcEndpoint", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.EC2.Model.CreateVpcEndpointResponse")]
[AWSCmdlet("Calls the Amazon Elastic Compute Cloud (EC2) CreateVpcEndpoint API operation.", Operation = new[] {"CreateVpcEndpoint"}, SelectReturnType = typeof(Amazon.EC2.Model.CreateVpcEndpointResponse))]
[AWSCmdletOutput("Amazon.EC2.Model.CreateVpcEndpointResponse",
"This cmdlet returns an Amazon.EC2.Model.CreateVpcEndpointResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewEC2VpcEndpointCmdlet : AmazonEC2ClientCmdlet, IExecutor
{
#region Parameter DnsOptions_DnsRecordIpType
///
///
/// The DNS records created for the endpoint.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.EC2.DnsRecordIpType")]
public Amazon.EC2.DnsRecordIpType DnsOptions_DnsRecordIpType { get; set; }
#endregion
#region Parameter IpAddressType
///
///
/// The IP address type for the endpoint.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.EC2.IpAddressType")]
public Amazon.EC2.IpAddressType IpAddressType { get; set; }
#endregion
#region Parameter PolicyDocument
///
///
/// (Interface and gateway endpoints) A policy to attach to the endpoint that controls
/// access to the service. The policy must be in valid JSON format. If this parameter
/// is not specified, we attach a default policy that allows full access to the service.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PolicyDocument { get; set; }
#endregion
#region Parameter PrivateDnsEnabled
///
///
/// (Interface endpoint) Indicates whether to associate a private hosted zone with the
/// specified VPC. The private hosted zone contains a record set for the default public
/// DNS name for the service for the Region (for example, kinesis.us-east-1.amazonaws.com
),
/// which resolves to the private IP addresses of the endpoint network interfaces in the
/// VPC. This enables you to make requests to the default public DNS name for the service
/// instead of the public DNS names that are automatically generated by the VPC endpoint
/// service.To use a private hosted zone, you must set the following VPC attributes to true
:
/// enableDnsHostnames
and enableDnsSupport
. Use ModifyVpcAttribute
/// to set the VPC attributes.Default: true
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? PrivateDnsEnabled { get; set; }
#endregion
#region Parameter DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint
///
///
/// Indicates whether to enable private DNS only for inbound endpoints. This option is
/// available only for services that support both gateway and interface endpoints. It
/// routes traffic that originates from the VPC to the gateway endpoint and traffic that
/// originates from on-premises to the interface endpoint.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint { get; set; }
#endregion
#region Parameter RouteTableId
///
///
/// (Gateway endpoint) The route table IDs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("RouteTableIds")]
public System.String[] RouteTableId { get; set; }
#endregion
#region Parameter SecurityGroupId
///
///
/// (Interface endpoint) The IDs of the security groups to associate with the endpoint
/// network interface. If this parameter is not specified, we use the default security
/// group for the VPC.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("SecurityGroupIds")]
public System.String[] SecurityGroupId { get; set; }
#endregion
#region Parameter ServiceName
///
///
/// The name of the endpoint service.
///
///
#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 ServiceName { get; set; }
#endregion
#region Parameter SubnetId
///
///
/// (Interface and Gateway Load Balancer endpoints) The IDs of the subnets in which to
/// create an endpoint network interface. For a Gateway Load Balancer endpoint, you can
/// specify only one subnet.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("SubnetIds")]
public System.String[] SubnetId { get; set; }
#endregion
#region Parameter TagSpecification
///
///
/// The tags to associate with the endpoint.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("TagSpecifications")]
public Amazon.EC2.Model.TagSpecification[] TagSpecification { get; set; }
#endregion
#region Parameter VpcEndpointType
///
///
/// The type of endpoint.Default: Gateway
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.EC2.VpcEndpointType")]
public Amazon.EC2.VpcEndpointType VpcEndpointType { get; set; }
#endregion
#region Parameter VpcId
///
///
/// The ID of the VPC.
///
///
#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 VpcId { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// Unique, case-sensitive identifier that you provide to ensure the idempotency of the
/// request. For more information, see How
/// to ensure idempotency.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.EC2.Model.CreateVpcEndpointResponse).
/// Specifying the name of a property of type Amazon.EC2.Model.CreateVpcEndpointResponse 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; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the VpcId parameter.
/// The -PassThru parameter is deprecated, use -Select '^VpcId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^VpcId' 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.VpcId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-EC2VpcEndpoint (CreateVpcEndpoint)"))
{
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.VpcId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.ClientToken = this.ClientToken;
context.DnsOptions_DnsRecordIpType = this.DnsOptions_DnsRecordIpType;
context.DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint = this.DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint;
context.IpAddressType = this.IpAddressType;
context.PolicyDocument = this.PolicyDocument;
context.PrivateDnsEnabled = this.PrivateDnsEnabled;
if (this.RouteTableId != null)
{
context.RouteTableId = new List(this.RouteTableId);
}
if (this.SecurityGroupId != null)
{
context.SecurityGroupId = new List(this.SecurityGroupId);
}
context.ServiceName = this.ServiceName;
#if MODULAR
if (this.ServiceName == null && ParameterWasBound(nameof(this.ServiceName)))
{
WriteWarning("You are passing $null as a value for parameter ServiceName 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.SubnetId != null)
{
context.SubnetId = new List(this.SubnetId);
}
if (this.TagSpecification != null)
{
context.TagSpecification = new List(this.TagSpecification);
}
context.VpcEndpointType = this.VpcEndpointType;
context.VpcId = this.VpcId;
#if MODULAR
if (this.VpcId == null && ParameterWasBound(nameof(this.VpcId)))
{
WriteWarning("You are passing $null as a value for parameter VpcId 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
// 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.EC2.Model.CreateVpcEndpointRequest();
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
// populate DnsOptions
var requestDnsOptionsIsNull = true;
request.DnsOptions = new Amazon.EC2.Model.DnsOptionsSpecification();
Amazon.EC2.DnsRecordIpType requestDnsOptions_dnsOptions_DnsRecordIpType = null;
if (cmdletContext.DnsOptions_DnsRecordIpType != null)
{
requestDnsOptions_dnsOptions_DnsRecordIpType = cmdletContext.DnsOptions_DnsRecordIpType;
}
if (requestDnsOptions_dnsOptions_DnsRecordIpType != null)
{
request.DnsOptions.DnsRecordIpType = requestDnsOptions_dnsOptions_DnsRecordIpType;
requestDnsOptionsIsNull = false;
}
System.Boolean? requestDnsOptions_dnsOptions_PrivateDnsOnlyForInboundResolverEndpoint = null;
if (cmdletContext.DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint != null)
{
requestDnsOptions_dnsOptions_PrivateDnsOnlyForInboundResolverEndpoint = cmdletContext.DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint.Value;
}
if (requestDnsOptions_dnsOptions_PrivateDnsOnlyForInboundResolverEndpoint != null)
{
request.DnsOptions.PrivateDnsOnlyForInboundResolverEndpoint = requestDnsOptions_dnsOptions_PrivateDnsOnlyForInboundResolverEndpoint.Value;
requestDnsOptionsIsNull = false;
}
// determine if request.DnsOptions should be set to null
if (requestDnsOptionsIsNull)
{
request.DnsOptions = null;
}
if (cmdletContext.IpAddressType != null)
{
request.IpAddressType = cmdletContext.IpAddressType;
}
if (cmdletContext.PolicyDocument != null)
{
request.PolicyDocument = cmdletContext.PolicyDocument;
}
if (cmdletContext.PrivateDnsEnabled != null)
{
request.PrivateDnsEnabled = cmdletContext.PrivateDnsEnabled.Value;
}
if (cmdletContext.RouteTableId != null)
{
request.RouteTableIds = cmdletContext.RouteTableId;
}
if (cmdletContext.SecurityGroupId != null)
{
request.SecurityGroupIds = cmdletContext.SecurityGroupId;
}
if (cmdletContext.ServiceName != null)
{
request.ServiceName = cmdletContext.ServiceName;
}
if (cmdletContext.SubnetId != null)
{
request.SubnetIds = cmdletContext.SubnetId;
}
if (cmdletContext.TagSpecification != null)
{
request.TagSpecifications = cmdletContext.TagSpecification;
}
if (cmdletContext.VpcEndpointType != null)
{
request.VpcEndpointType = cmdletContext.VpcEndpointType;
}
if (cmdletContext.VpcId != null)
{
request.VpcId = cmdletContext.VpcId;
}
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.EC2.Model.CreateVpcEndpointResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.CreateVpcEndpointRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "CreateVpcEndpoint");
try
{
#if DESKTOP
return client.CreateVpcEndpoint(request);
#elif CORECLR
return client.CreateVpcEndpointAsync(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 ClientToken { get; set; }
public Amazon.EC2.DnsRecordIpType DnsOptions_DnsRecordIpType { get; set; }
public System.Boolean? DnsOptions_PrivateDnsOnlyForInboundResolverEndpoint { get; set; }
public Amazon.EC2.IpAddressType IpAddressType { get; set; }
public System.String PolicyDocument { get; set; }
public System.Boolean? PrivateDnsEnabled { get; set; }
public List RouteTableId { get; set; }
public List SecurityGroupId { get; set; }
public System.String ServiceName { get; set; }
public List SubnetId { get; set; }
public List TagSpecification { get; set; }
public Amazon.EC2.VpcEndpointType VpcEndpointType { get; set; }
public System.String VpcId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}