コード例 #1
0
        /// <summary>Initializes a new instance of the <see cref="CloudFormationRunner"/> class.</summary>
        /// <param name="clientFactory">Factory for creating AWS service clients</param>
        /// <param name="stackName">Name of the stack.</param>
        /// <param name="templateLocation">Template location. Either path or URL.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="capabilities">The capabilities.</param>
        /// <param name="context">The Cake context.</param>
        /// <param name="tags">Stack level tags.</param>
        /// <param name="followOperation">if set to <c>true</c> [follow operation].</param>
        /// <param name="waitForInProgressUpdate">if set to <c>true</c> [wait for in progress update].</param>
        /// <param name="deleteNoopChangeSet">if set to <c>true</c> [delete no-op change set].</param>
        /// <param name="changesetOnly">if set to <c>true</c> only create change set without updating.</param>
        /// <param name="resourcesToImportLocation">Resources to import</param>
        /// <param name="roleArn">Role to assume</param>
        /// <param name="clientToken">Client token</param>
        /// <param name="notificationARNs">SNS notification ARNs</param>
        /// <param name="usePreviousTemplate">Whether to use existing template for update.</param>
        /// <param name="rollbackConfiguration">The rollback configuration</param>
        /// <param name="stackPolicyLocation">Location of structure containing a new stack policy body.</param>
        /// <param name="stackPolicyDuringUpdateLocation">Location of structure containing the temporary overriding stack policy body</param>
        /// <param name="resourceType">The template resource types that you have permissions to work with for this create stack action.</param>
        /// <param name="terminationProtection">Whether to enable termination protection on the specified stack.</param>
        /// <param name="onFailure">Determines what action will be taken if stack creation fails.</param>
        /// <param name="timeoutInMinutes">The amount of time that can pass before the stack status becomes CREATE_FAILED</param>
        /// <param name="disableRollback">Set to <c>true</c> to disable rollback of the stack if stack creation failed.</param>
        /// <param name="retainResource">For stacks in the DELETE_FAILED state, a list of resource logical IDs that are associated with the resources you want to retain.</param>
        /// <param name="forceS3">If <c>true</c> always upload local templates to S3.</param>
        /// <param name="includeNestedStacks">Creates a change set for the all nested stacks specified in the template. The default behavior of this action is set to <c>false</c>. To include nested sets in a change set, specify <c>true</c>.</param>
        /// <remarks>Constructor is private as this class implements the builder pattern. See CloudFormation.Runner.Builder.cs</remarks>
        internal CloudFormationRunner(
            IAwsClientFactory clientFactory,
            string stackName,
            string templateLocation,
            IDictionary <string, string> parameters,
            IEnumerable <Capability> capabilities,
            ICloudFormationContext context,
            List <Tag> tags,
            bool followOperation,
            bool waitForInProgressUpdate,
            bool deleteNoopChangeSet,
            bool changesetOnly,
            string resourcesToImportLocation,
            string roleArn,
            string clientToken,
            // ReSharper disable once InconsistentNaming
            List <string> notificationARNs,
            bool usePreviousTemplate,
            RollbackConfiguration rollbackConfiguration,
            string stackPolicyLocation,
            string stackPolicyDuringUpdateLocation,
            List <string> resourceType,
            bool terminationProtection,
            OnFailure onFailure,
            int timeoutInMinutes,
            bool disableRollback,
            List <string> retainResource,
            bool forceS3,
            bool includeNestedStacks)
        {
            this.includeNestedStacks             = includeNestedStacks;
            this.forceS3                         = forceS3;
            this.retainResource                  = retainResource;
            this.disableRollback                 = disableRollback;
            this.timeoutInMinutes                = timeoutInMinutes;
            this.onFailure                       = onFailure;
            this.terminationProtection           = terminationProtection;
            this.resourceType                    = resourceType;
            this.stackPolicyDuringUpdateLocation = stackPolicyDuringUpdateLocation;
            this.stackPolicyLocation             = stackPolicyLocation;
            this.rollbackConfiguration           = rollbackConfiguration;
            this.usePreviousTemplate             = usePreviousTemplate;
            this.notificationARNs                = notificationARNs;
            this.clientToken                     = clientToken;
            this.roleArn                         = roleArn;
            this.resourcesToImportLocation       = resourcesToImportLocation;
            this.clientFactory                   = clientFactory;
            this.context                         = context;
            this.changesetOnly                   = changesetOnly;
            this.templateLocation                = templateLocation;
            this.stackName                       = stackName ?? throw new ArgumentNullException(nameof(stackName));
            this.followOperation                 = followOperation;
            this.waitForInProgressUpdate         = waitForInProgressUpdate;
            this.deleteNoopChangeSet             = deleteNoopChangeSet;

            // Cheeky unit test detection
            if (context.GetType().FullName == "Castle.Proxies.ICloudFormationContextProxy")
            {
                // Don't hang around in the wait loop
                this.waitPollTime = 50;
            }

            if (capabilities != null)
            {
                this.capabilities = capabilities;
            }

            if (parameters != null)
            {
                this.parameters = parameters;
            }

            if (tags != null)
            {
                this.tags = tags;
            }

            this.client          = this.clientFactory.CreateCloudFormationClient();
            this.stackOperations = new CloudFormationOperations(this.clientFactory, this.context);

            // Get parameters and description from supplied template if any
            this.templateResolver = new TemplateResolver(this.clientFactory, this.context, this.stackName, this.usePreviousTemplate, this.forceS3);

            this.templateResolver.ResolveArtifactLocationAsync(this.context, this.templateLocation, this.stackName)
            .Wait();

            if (this.templateResolver.Source != InputFileSource.None)
            {
                var parser = TemplateParser.Create(this.templateResolver.FileContent);

                this.templateDescription = parser.GetTemplateDescription();

                // Adds base stack name + 10 chars to each nested stack to estimate logical resource ID of each nested stack
                this.context.Logger.SetStackNameColumnWidth(
                    parser.GetNestedStackNames(this.stackName).Concat(new[] { this.stackName })
                    .Max(s => s.Length));

                this.context.Logger.SetResourceNameColumnWidth(parser.GetLogicalResourceNames(this.stackName).Max(r => r.Length));
            }
        }
コード例 #2
0
 /// <summary>
 /// Adds a rollback configuration.
 /// See <seealso href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-rollback-triggers.html"/>.
 /// </summary>
 /// <param name="rollbackConfiguration">The rollback configuration.</param>
 /// <returns>The builder</returns>
 public CloudFormationBuilder WithRollbackConfiguration(RollbackConfiguration rollbackConfiguration)
 {
     this._rollbackConfiguration = rollbackConfiguration;
     return(this);
 }