/*******************************************************************************
* 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.DocDB;
using Amazon.DocDB.Model;
namespace Amazon.PowerShell.Cmdlets.DOC
{
///
/// Creates a new instance.
///
[Cmdlet("New", "DOCDBInstance", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.DocDB.Model.DBInstance")]
[AWSCmdlet("Calls the Amazon DocumentDB (with MongoDB compatibility) CreateDBInstance API operation.", Operation = new[] {"CreateDBInstance"}, SelectReturnType = typeof(Amazon.DocDB.Model.CreateDBInstanceResponse))]
[AWSCmdletOutput("Amazon.DocDB.Model.DBInstance or Amazon.DocDB.Model.CreateDBInstanceResponse",
"This cmdlet returns an Amazon.DocDB.Model.DBInstance object.",
"The service call response (type Amazon.DocDB.Model.CreateDBInstanceResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewDOCDBInstanceCmdlet : AmazonDocDBClientCmdlet, IExecutor
{
#region Parameter AutoMinorVersionUpgrade
///
///
/// This parameter does not apply to Amazon DocumentDB. Amazon DocumentDB does not perform
/// minor version upgrades regardless of the value set.Default: false
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? AutoMinorVersionUpgrade { get; set; }
#endregion
#region Parameter AvailabilityZone
///
///
/// The Amazon EC2 Availability Zone that the instance is created in. Default: A random, system-chosen Availability Zone in the endpoint's Amazon Web Services
/// Region.Example: us-east-1d
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AvailabilityZone { get; set; }
#endregion
#region Parameter CopyTagsToSnapshot
///
///
/// A value that indicates whether to copy tags from the DB instance to snapshots of the
/// DB instance. By default, tags are not copied.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? CopyTagsToSnapshot { get; set; }
#endregion
#region Parameter DBClusterIdentifier
///
///
/// The identifier of the cluster that the instance will belong to.
///
///
#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 DBClusterIdentifier { get; set; }
#endregion
#region Parameter DBInstanceClass
///
///
/// The compute and memory capacity of the instance; for example, db.r5.large
.
///
///
///
#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 DBInstanceClass { get; set; }
#endregion
#region Parameter DBInstanceIdentifier
///
///
/// The instance identifier. This parameter is stored as a lowercase string.Constraints:- Must contain from 1 to 63 letters, numbers, or hyphens.
- The first character must be a letter.
- Cannot end with a hyphen or contain two consecutive hyphens.
Example: mydbinstance
///
///
#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 DBInstanceIdentifier { get; set; }
#endregion
#region Parameter EnablePerformanceInsight
///
///
/// A value that indicates whether to enable Performance Insights for the DB Instance.
/// For more information, see Using
/// Amazon Performance Insights.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("EnablePerformanceInsights")]
public System.Boolean? EnablePerformanceInsight { get; set; }
#endregion
#region Parameter Engine
///
///
/// The name of the database engine to be used for this instance.Valid value: docdb
///
///
#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 Engine { get; set; }
#endregion
#region Parameter PerformanceInsightsKMSKeyId
///
///
/// The KMS key identifier for encryption of Performance Insights data.The KMS key identifier is the key ARN, key ID, alias ARN, or alias name for the KMS
/// key.If you do not specify a value for PerformanceInsightsKMSKeyId, then Amazon DocumentDB
/// uses your default KMS key. There is a default KMS key for your Amazon Web Services
/// account. Your Amazon Web Services account has a different default KMS key for each
/// Amazon Web Services region.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PerformanceInsightsKMSKeyId { get; set; }
#endregion
#region Parameter PreferredMaintenanceWindow
///
///
/// The time range each week during which system maintenance can occur, in Universal Coordinated
/// Time (UTC). Format: ddd:hh24:mi-ddd:hh24:mi
The default is a 30-minute window selected at random from an 8-hour block of time
/// for each Amazon Web Services Region, occurring on a random day of the week. Valid days: Mon, Tue, Wed, Thu, Fri, Sat, SunConstraints: Minimum 30-minute window.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PreferredMaintenanceWindow { get; set; }
#endregion
#region Parameter PromotionTier
///
///
/// A value that specifies the order in which an Amazon DocumentDB replica is promoted
/// to the primary instance after a failure of the existing primary instance.Default: 1Valid values: 0-15
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? PromotionTier { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tags to be assigned to the instance. You can assign up to 10 tags to an instance.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.DocDB.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'DBInstance'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DocDB.Model.CreateDBInstanceResponse).
/// Specifying the name of a property of type Amazon.DocDB.Model.CreateDBInstanceResponse 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; } = "DBInstance";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the DBInstanceIdentifier parameter.
/// The -PassThru parameter is deprecated, use -Select '^DBInstanceIdentifier' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^DBInstanceIdentifier' 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.DBInstanceIdentifier), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DOCDBInstance (CreateDBInstance)"))
{
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.DBInstanceIdentifier;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AutoMinorVersionUpgrade = this.AutoMinorVersionUpgrade;
context.AvailabilityZone = this.AvailabilityZone;
context.CopyTagsToSnapshot = this.CopyTagsToSnapshot;
context.DBClusterIdentifier = this.DBClusterIdentifier;
#if MODULAR
if (this.DBClusterIdentifier == null && ParameterWasBound(nameof(this.DBClusterIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter DBClusterIdentifier 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.DBInstanceClass = this.DBInstanceClass;
#if MODULAR
if (this.DBInstanceClass == null && ParameterWasBound(nameof(this.DBInstanceClass)))
{
WriteWarning("You are passing $null as a value for parameter DBInstanceClass 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.DBInstanceIdentifier = this.DBInstanceIdentifier;
#if MODULAR
if (this.DBInstanceIdentifier == null && ParameterWasBound(nameof(this.DBInstanceIdentifier)))
{
WriteWarning("You are passing $null as a value for parameter DBInstanceIdentifier 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.EnablePerformanceInsight = this.EnablePerformanceInsight;
context.Engine = this.Engine;
#if MODULAR
if (this.Engine == null && ParameterWasBound(nameof(this.Engine)))
{
WriteWarning("You are passing $null as a value for parameter Engine 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.PerformanceInsightsKMSKeyId = this.PerformanceInsightsKMSKeyId;
context.PreferredMaintenanceWindow = this.PreferredMaintenanceWindow;
context.PromotionTier = this.PromotionTier;
if (this.Tag != null)
{
context.Tag = new List(this.Tag);
}
// 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.DocDB.Model.CreateDBInstanceRequest();
if (cmdletContext.AutoMinorVersionUpgrade != null)
{
request.AutoMinorVersionUpgrade = cmdletContext.AutoMinorVersionUpgrade.Value;
}
if (cmdletContext.AvailabilityZone != null)
{
request.AvailabilityZone = cmdletContext.AvailabilityZone;
}
if (cmdletContext.CopyTagsToSnapshot != null)
{
request.CopyTagsToSnapshot = cmdletContext.CopyTagsToSnapshot.Value;
}
if (cmdletContext.DBClusterIdentifier != null)
{
request.DBClusterIdentifier = cmdletContext.DBClusterIdentifier;
}
if (cmdletContext.DBInstanceClass != null)
{
request.DBInstanceClass = cmdletContext.DBInstanceClass;
}
if (cmdletContext.DBInstanceIdentifier != null)
{
request.DBInstanceIdentifier = cmdletContext.DBInstanceIdentifier;
}
if (cmdletContext.EnablePerformanceInsight != null)
{
request.EnablePerformanceInsights = cmdletContext.EnablePerformanceInsight.Value;
}
if (cmdletContext.Engine != null)
{
request.Engine = cmdletContext.Engine;
}
if (cmdletContext.PerformanceInsightsKMSKeyId != null)
{
request.PerformanceInsightsKMSKeyId = cmdletContext.PerformanceInsightsKMSKeyId;
}
if (cmdletContext.PreferredMaintenanceWindow != null)
{
request.PreferredMaintenanceWindow = cmdletContext.PreferredMaintenanceWindow;
}
if (cmdletContext.PromotionTier != null)
{
request.PromotionTier = cmdletContext.PromotionTier.Value;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
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.DocDB.Model.CreateDBInstanceResponse CallAWSServiceOperation(IAmazonDocDB client, Amazon.DocDB.Model.CreateDBInstanceRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon DocumentDB (with MongoDB compatibility)", "CreateDBInstance");
try
{
#if DESKTOP
return client.CreateDBInstance(request);
#elif CORECLR
return client.CreateDBInstanceAsync(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.Boolean? AutoMinorVersionUpgrade { get; set; }
public System.String AvailabilityZone { get; set; }
public System.Boolean? CopyTagsToSnapshot { get; set; }
public System.String DBClusterIdentifier { get; set; }
public System.String DBInstanceClass { get; set; }
public System.String DBInstanceIdentifier { get; set; }
public System.Boolean? EnablePerformanceInsight { get; set; }
public System.String Engine { get; set; }
public System.String PerformanceInsightsKMSKeyId { get; set; }
public System.String PreferredMaintenanceWindow { get; set; }
public System.Int32? PromotionTier { get; set; }
public List Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.DBInstance;
}
}
}