public void CreatesStackWithOversizedTemplates()
        {
            string stackName = "ProvisioningTest-CreatesStackWithOversizedTemplates";
            SetUp(stackName);

            try
            {
                var deployer = new Deployer(_awsConfiguration);

                deployer.CreateStack(new StackTemplate
                {
                    StackName = stackName,
                    TemplatePath = CloudFormationTemplates.Path("example-oversize.template")
                });

                var status = StackStatus.CREATE_IN_PROGRESS;
                while (status == StackStatus.CREATE_IN_PROGRESS)
                {
                    var stack =
                        _cloudFormationClient.DescribeStacks(new DescribeStacksRequest { StackName = stackName })
                                             .Stacks.First();
                    status = stack.StackStatus;
                    if (status == StackStatus.CREATE_IN_PROGRESS) Thread.Sleep(TimeSpan.FromSeconds(10));
                }

                Assert.AreEqual(status, StackStatus.CREATE_COMPLETE);
            }
            finally
            {
                DeleteTestStack(stackName);
            }
        }
Exemple #2
0
        public void ThrowsWhenStackFailsToDetele()
        {
            var stackName = "AwsToolsRemovalThrowsWhenStackFailsToDeteleTest";
            var securityGroupName = "AwsToolsRemovalThrowsWhenStackFailsToDeteleTest";
            SetUp(stackName);

            var deployer = new Deployer(_awsConfiguration);
            try
            {
                deployer.CreateStack(new StackTemplate
                    {
                        StackName = stackName,
                        TemplatePath = CloudFormationTemplates.Path("example-basic-vpc.template")
                    });
                CreateSecurityGroup(securityGroupName, stackName);

                TestDelegate act = () => deployer.DeleteStack(stackName);

                Assert.Throws<FailedToDeleteStackException>(act);
            }
            finally
            {
                DeleteSecurityGroup(securityGroupName, stackName);
                DeletePreviousTestStack(stackName);
            }
        }
        public void EnsureStackExists()
        {
            if (_hasCreatedStack) return;

            _awsConfiguration = new AwsConfiguration
            {
                AssumeRoleTrustDocument = Roles.Path("code-deploy-trust.json"),
                IamRolePolicyDocument = Roles.Path("code-deploy-policy.json"),
                Bucket = "aws-deployment-tools-tests",
                RoleName = "CodeDeployRole",
                AwsEndpoint = TestConfiguration.AwsEndpoint,
                Credentials = new TestSuiteCredentials()
            };

            _iamClient = new AmazonIdentityManagementServiceClient(
                new AmazonIdentityManagementServiceConfig
                {
                    RegionEndpoint = _awsConfiguration.AwsEndpoint,
                    ProxyHost = _awsConfiguration.ProxyHost,
                    ProxyPort = _awsConfiguration.ProxyPort
                });

            DeletePreviousTestStack();

            _deployer = new Deployer(_awsConfiguration);

            _stack = _deployer.CreateStack(new StackTemplate
            {
                StackName = StackName,
                TemplatePath = CloudFormationTemplates.Path("example-windows-vpc-autoscaling-group.template")
            });
            _hasCreatedStack = true;
        }
Exemple #4
0
        public void CreatesBucketBasedOnRoleThatCanAssumeAppropriateRole()
        {
            var createBucketRole = _iamClient.PutRolePolicy(new PutRolePolicyRequest
            {
                RoleName = _roleToAssume.RoleName,
                PolicyName = "assume-policy-8",
                PolicyDocument = @"{
                  ""Version"": ""2012-10-17"",
                  ""Statement"": [
                    {
                      ""Effect"": ""Allow"",
                      ""Action"": [
                        ""s3:*"",
                        ""cloudformation:*""
                      ],
                      ""Resource"": [
                        ""*""
                      ]
                    }
                  ]
                }"
            });

            Thread.Sleep(TimeSpan.FromSeconds(10));

            var deployer = new Deployer(_awsConfiguration);
            //deployer.CreateStack(new StackTemplate {
            //    StackName = "SimpleBucketTestStack",
            //    TemplatePath = CloudFormationTemplates.Path("simple-s3-bucket.template"),
            //});

            //var s3Response = _s3Client.GetBucketLocation(_bucketName);
            //Assert.AreEqual(s3Response.HttpStatusCode, HttpStatusCode.OK);
        }
Exemple #5
0
        public void DoesNotThrowWhenStackDoesNotExist()
        {
            var stackName = "AwsToolsRemovalDoesNotThrowWhenStackDoesNotExistTest";
            SetUp(stackName);
            var deployer = new Deployer(_awsConfiguration);
            var stack = _cloudFormationClient.ListStacks().StackSummaries.FirstOrDefault(s => s.StackName == stackName);

            Assert.IsTrue(stack == null || stack.StackStatus == StackStatus.DELETE_COMPLETE, "Stack should not exist!");

            TestDelegate act = () => deployer.DeleteStack(stackName);

            Assert.DoesNotThrow(act);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options))
                Environment.Exit(1);

            var deployer = new Deployer(new AwsConfiguration
            {
                AwsEndpoint = RegionEndpoint.GetBySystemName(options.Region),
                RoleName = options.RoleName,
                Proxy = new AwsProxy { Host = options.ProxyHost, Port = options.ProxyPort }
            });
            deployer.DeleteStack(options.StackName);
        }
 public void CreatingStackCapturesOutputs()
 {
     var deployer = new Deployer(new AwsConfiguration
     {
         AwsEndpoint = TestConfiguration.AwsEndpoint,
         Credentials = new TestSuiteCredentials(),
         Bucket = "aws-deployment-tools-tests"
     });
     var stack = deployer.CreateStack(new StackTemplate
     {
         StackName = _stackName,
         TemplatePath = CloudFormationTemplates.Path("stack-outputs.template")
     });
     Assert.That(stack.Outputs["outputA"], Is.EqualTo("123"));
     Assert.That(stack.Outputs["outputB"], Is.EqualTo("456"));
 }
Exemple #8
0
        public void DeletesExistingStack()
        {
            var stackName = "AwsToolsRemovalDeletesExistingStackTest";
            SetUp(stackName);

            var deployer = new Deployer(_awsConfiguration);
            deployer.CreateStack(new StackTemplate
            {
                StackName = stackName,
                TemplatePath = CloudFormationTemplates.Path("example-basic-vpc.template")
            });

            deployer.DeleteStack(stackName);

            var status = StackStatus.DELETE_IN_PROGRESS;
            status = WaitForStackDeleted(status, stackName);

            Assert.AreEqual(StackStatus.DELETE_COMPLETE, status);
        }
        public void CreatesStackWithParameters()
        {
            var stackName = "ProvisioningTest-CreatesStackWithParameters";
            SetUp(stackName);
            try
            {
                var deployer = new Deployer(_awsConfiguration);

                deployer.CreateStack(new StackTemplate
                    {
                        StackName = stackName,
                        TemplatePath = CloudFormationTemplates.Path("example-parameters.template"),
                        ParameterPath = CloudFormationTemplates.Path("example-parameters.parameters")
                    });

                var status = StackStatus.CREATE_IN_PROGRESS;
                while (status == StackStatus.CREATE_IN_PROGRESS)
                {
                    var stack =
                        _cloudFormationClient.DescribeStacks(new DescribeStacksRequest {StackName = stackName})
                                             .Stacks.First();
                    status = stack.StackStatus;
                    if (status == StackStatus.CREATE_IN_PROGRESS) Thread.Sleep(TimeSpan.FromSeconds(10));
                }

                var vpcId =
                    _cloudFormationClient.DescribeStackResource(new DescribeStackResourceRequest
                        {
                            LogicalResourceId = "vpc1",
                            StackName = stackName
                        }).StackResourceDetail.PhysicalResourceId;
                var vpc = _ec2Client.DescribeVpcs(new DescribeVpcsRequest {VpcIds = new List<string> {vpcId}}).Vpcs.First();
                var vpcName = vpc.Tags.First(tag => tag.Key == "Name").Value;

                Assert.AreEqual(status, StackStatus.CREATE_COMPLETE);
                Assert.AreEqual("TestVpcName", vpcName);
            }
            finally
            {
                DeleteTestStack(stackName);
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options)) return;

            var deployer = new Deployer(new AwsConfiguration
            {
                AssumeRoleTrustDocument = options.AssumeRolePolicyPath,
                IamRolePolicyDocument = options.S3AccessPolicyDocumentPath,
                Bucket = options.BucketName,
                RoleName = "S3-Push",
                AwsEndpoint = RegionEndpoint.GetBySystemName(options.RegionEndpoint)
            });

            deployer.PushRevision(new ApplicationSetRevision
            {
               LocalDirectory  = options.BuildDirectoryPath,
               Version = options.Version,
               ApplicationSetName = options.ApplicationSetName
            });
        }
Exemple #11
0
        public void EnsureStackExists()
        {
            if (_hasCreatedStack) return;

            _awsConfiguration = new AwsConfiguration
            {
                AssumeRoleTrustDocument = Roles.Path("code-deploy-trust.json"),
                IamRolePolicyDocument = Roles.Path("code-deploy-policy.json"),
                Bucket = "aws-deployment-tools-tests",
                RoleName = "CodeDeployRole",
                AwsEndpoint = TestConfiguration.AwsEndpoint,
                Credentials = new TestSuiteCredentials()
            };

            _deployer = new Deployer(_awsConfiguration);

            DeletePreviousTestStack();
            _stack = _deployer.CreateStack(new StackTemplate
            {
                StackName = StackName,
                TemplatePath = CloudFormationTemplates.Path("example-windows-vpc.template")
            });
            _hasCreatedStack = true;
        }
Exemple #12
0
        public void SetUp()
        {
            var awsEndpoint = TestConfiguration.AwsEndpoint;
            var credentials = new TestSuiteCredentials();

            _s3Client = new AmazonS3Client(awsEndpoint);
            _iamClient = new AmazonIdentityManagementServiceClient(awsEndpoint);

            _awsConfiguration = new AwsConfiguration
            {
                IamRolePolicyDocument = Roles.Path("s3-policy-new-bucket.json"),
                AssumeRoleTrustDocument = Roles.Path("code-deploy-trust.json"),
                Bucket = "s3-push-test",
                RoleName = "SomeNewRole",
                AwsEndpoint = awsEndpoint,
                Credentials = credentials
            };

            _deployer = new Deployer(_awsConfiguration);
            _localBuildDirectory = ExampleRevisions.Directory("HelloWorld-1.2.3");
            _applicationSetName = "HelloWorld";
            _version = "1.1.1";
            DeleteRolesAndPolicies();
        }
Exemple #13
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options))
                Environment.Exit(1);

            var deployer = new Deployer(new AwsConfiguration
            {
                AwsEndpoint = RegionEndpoint.GetBySystemName(options.Region),
                RoleName = options.RoleName,
                Proxy = new AwsProxy { Host = options.ProxyHost, Port = options.ProxyPort },
                Bucket = options.BucketName
            });
            deployer.CreateStack(new StackTemplate
            {
                StackName = options.StackName,
                TemplatePath = options.TemplatePath,
                ParameterPath = options.ParameterPath
            });
        }
Exemple #14
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options))
                Environment.Exit(1);

            var deployer = new Deployer(new AwsConfiguration
            {
                AssumeRoleTrustDocument = options.AssumeRolePolicyPath,
                IamRolePolicyDocument = options.S3AccessPolicyDocumentPath,
                Bucket = options.BucketName,
                RoleName = options.RoleName,
                CodeDeployRoleName = options.CodeDeployRoleName,
                AwsEndpoint = RegionEndpoint.GetBySystemName(options.RegionEndpoint),
                Proxy = new AwsProxy{ Host = options.ProxyHost, Port = options.ProxyPort }
            });
            var revision = deployer.PushRevision(new ApplicationSetRevision
            {
                ApplicationSetName = options.ApplicationSetName,
                StackName = options.StackName,
                Version = options.Version,
                LocalDirectory = options.BuildDirectoryPath
            });
            try
            {
                deployer.DeployRelease(revision, options.CodeDeployRoleName);
            }
            catch (Exception e)
            {
                Console.WriteLine("AWS Push And Deploy Error:");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Environment.Exit(666);
            }
        }