Exemplo n.º 1
0
    public MyStack()
    {
        // Create a new security group for port 80.
        var securityGroup = new Aws.Ec2.SecurityGroup("securityGroup", new Aws.Ec2.SecurityGroupArgs
        {
            Ingress =
            {
                new Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "tcp",
                    FromPort   = 0,
                    ToPort     = 0,
                    CidrBlocks =
                    {
                        "0.0.0.0/0",
                    },
                },
            },
        });
        var ami = Output.Create(Aws.GetAmi.InvokeAsync(new Aws.GetAmiArgs
        {
            Filters =
            {
                new Aws.Inputs.GetAmiFilterArgs
                {
                    Name   = "name",
                    Values =
                    {
                        "amzn-ami-hvm-*-x86_64-ebs",
                    },
                },
            },
            Owners =
            {
                "137112412989",
            },
            MostRecent = true,
        }));
        // Create a simple web server using the startup script for the instance.
        var server = new Aws.Ec2.Instance("server", new Aws.Ec2.InstanceArgs
        {
            Tags =
            {
                { "Name", "web-server-www" },
            },
            InstanceType   = "t2.micro",
            SecurityGroups =
            {
                securityGroup.Name,
            },
            Ami      = ami.Apply(ami => ami.Id),
            UserData = @"#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
",
        });

        this.PublicIp       = server.PublicIp;
        this.PublicHostName = server.PublicDns;
    }
Exemplo n.º 2
0
 public MyStack()
 {
     var subnetId = Output.Create(Aws.CloudFormation.GetExport.InvokeAsync(new Aws.CloudFormation.GetExportArgs
     {
         Name = "mySubnetIdExportName",
     }));
     var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
     {
         Ami          = "ami-abb07bcb",
         InstanceType = "t1.micro",
         SubnetId     = subnetId.Apply(subnetId => subnetId.Value),
     });
 }
Exemplo n.º 3
0
    public MyStack()
    {
        var ami = Output.Create(Pulumi.Aws.Invokes.GetAmi(new Pulumi.Aws.GetAmiArgs
        {
            MostRecent = true,
            Owners     = { "137112412989" },
            Filters    = { new Pulumi.Aws.Inputs.GetAmiFiltersArgs
                           {
                               Name = "name", Values = { "amzn-ami-hvm-*" }
                           } }
        }));

        var group = new Pulumi.Aws.Ec2.SecurityGroup("web-secgrp", new Pulumi.Aws.Ec2.SecurityGroupArgs
        {
            Description = "Enable HTTP access",
            Ingress     =
            {
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "tcp",
                    FromPort   = 80,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                },
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "icmp",
                    FromPort   = 8,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                }
            }
        });

        var userData = @"
#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
";

        var server = new Pulumi.Aws.Ec2.Instance("web-server-www", new Pulumi.Aws.Ec2.InstanceArgs
        {
            InstanceType        = "t2.micro",
            VpcSecurityGroupIds = { group.Id },
            UserData            = userData,
            Ami = ami.Apply(a => a.Id)
        });

        this.PublicIp  = server.PublicIp;
        this.PublicDns = server.PublicDns;
    }
Exemplo n.º 4
0
 public MyStack()
 {
     var testTargetGroup = new Aws.LB.TargetGroup("testTargetGroup", new Aws.LB.TargetGroupArgs
     {
     });
     var testInstance = new Aws.Ec2.Instance("testInstance", new Aws.Ec2.InstanceArgs
     {
     });
     var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("testTargetGroupAttachment", new Aws.LB.TargetGroupAttachmentArgs
     {
         Port           = 80,
         TargetGroupArn = testTargetGroup.Arn,
         TargetId       = testInstance.Id,
     });
 }
Exemplo n.º 5
0
 public MyStack()
 {
     var network = Output.Create(Aws.CloudFormation.GetStack.InvokeAsync(new Aws.CloudFormation.GetStackArgs
     {
         Name = "my-network-stack",
     }));
     var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
     {
         Ami          = "ami-abb07bcb",
         InstanceType = "t1.micro",
         SubnetId     = network.Apply(network => network.Outputs.SubnetId),
         Tags         =
         {
             { "Name", "HelloWorld" },
         },
     });
 }
Exemplo n.º 6
0
 public MyStack()
 {
     var ami = Output.Create(Aws.GetAmi.InvokeAsync(new Aws.GetAmiArgs
     {
         Filters =
         {
             new Aws.Inputs.GetAmiFilterArgs
             {
                 Name   = "name",
                 Values =
                 {
                     "amzn-ami-hvm-*",
                 },
             },
         },
         MostRecent = true,
         Owners     =
         {
             "amazon",
         },
     }));
     var instance = new Aws.Ec2.Instance("instance", new Aws.Ec2.InstanceArgs
     {
         Ami          = ami.Apply(ami => ami.Id),
         InstanceType = "t2.micro",
         Tags         =
         {
             { "type", "test-instance" },
         },
     });
     var sg = new Aws.Ec2.SecurityGroup("sg", new Aws.Ec2.SecurityGroupArgs
     {
         Tags =
         {
             { "type", "test-security-group" },
         },
     });
     var sgAttachment = new Aws.Ec2.NetworkInterfaceSecurityGroupAttachment("sgAttachment", new Aws.Ec2.NetworkInterfaceSecurityGroupAttachmentArgs
     {
         NetworkInterfaceId = instance.PrimaryNetworkInterfaceId,
         SecurityGroupId    = sg.Id,
     });
 }
Exemplo n.º 7
0
 public MyStack()
 {
     var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
     {
         Ami = "ami-21f78e11",
         AvailabilityZone = "us-west-2a",
         InstanceType     = "t1.micro",
         Tags             =
         {
             { "Name", "HelloWorld" },
         },
     });
     var example = new Aws.Ec2.Eip("example", new Aws.Ec2.EipArgs
     {
         Vpc = true,
     });
     var eipAssoc = new Aws.Ec2.EipAssociation("eipAssoc", new Aws.Ec2.EipAssociationArgs
     {
         AllocationId = example.Id,
         InstanceId   = web.Id,
     });
 }
Exemplo n.º 8
0
 public MyStack()
 {
     var ubuntu = Output.Create(Aws.GetAmi.InvokeAsync(new Aws.GetAmiArgs
     {
         Filters =
         {
             new Aws.Inputs.GetAmiFilterArgs
             {
                 Name   = "name",
                 Values =
                 {
                     "ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*",
                 },
             },
             new Aws.Inputs.GetAmiFilterArgs
             {
                 Name   = "virtualization-type",
                 Values =
                 {
                     "hvm",
                 },
             },
         },
         MostRecent = true,
         Owners     =
         {
             "099720109477",
         },
     }));
     var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
     {
         Ami          = ubuntu.Apply(ubuntu => ubuntu.Id),
         InstanceType = "t2.micro",
         Tags         =
         {
             { "Name", "HelloWorld" },
         },
     });
 }
Exemplo n.º 9
0
 public MyStack()
 {
     var web = new Aws.Ec2.Instance("web", new Aws.Ec2.InstanceArgs
     {
         Ami = "ami-21f78e11",
         AvailabilityZone = "us-west-2a",
         InstanceType     = "t1.micro",
         Tags             =
         {
             { "Name", "HelloWorld" },
         },
     });
     var example = new Aws.Ebs.Volume("example", new Aws.Ebs.VolumeArgs
     {
         AvailabilityZone = "us-west-2a",
         Size             = 1,
     });
     var ebsAtt = new Aws.Ec2.VolumeAttachment("ebsAtt", new Aws.Ec2.VolumeAttachmentArgs
     {
         DeviceName = "/dev/sdh",
         InstanceId = web.Id,
         VolumeId   = example.Id,
     });
 }
Exemplo n.º 10
0
    public MyStack()
    {
        var vpc = Output.Create(Pulumi.Aws.Ec2.GetVpc.InvokeAsync(new Pulumi.Aws.Ec2.GetVpcArgs {
            Default = true
        }));
        var vpcId  = vpc.Apply(vpc => vpc.Id);
        var subnet = vpcId.Apply(id => Pulumi.Aws.Ec2.GetSubnetIds.InvokeAsync(new Pulumi.Aws.Ec2.GetSubnetIdsArgs {
            VpcId = id
        }));
        var subnetIds = subnet.Apply(s => s.Ids);

        var ami = Output.Create(Pulumi.Aws.GetAmi.InvokeAsync(new Pulumi.Aws.GetAmiArgs
        {
            MostRecent = true,
            Owners     = { "137112412989" },
            Filters    = { new Pulumi.Aws.Inputs.GetAmiFiltersArgs
                           {
                               Name = "name", Values = { "amzn-ami-hvm-*" }
                           } }
        }));

        var group = new Pulumi.Aws.Ec2.SecurityGroup("web-secgrp", new Pulumi.Aws.Ec2.SecurityGroupArgs
        {
            Description = "Enable HTTP access",
            Egress      =
            {
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupEgressArgs
                {
                    Protocol   = "-1",
                    FromPort   = 0,
                    ToPort     = 0,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                },
            },
            Ingress =
            {
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "tcp",
                    FromPort   = 80,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                },
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "icmp",
                    FromPort   = 8,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                }
            }
        });

        var loadbalancer = new Pulumi.Aws.LB.LoadBalancer("external-loadbalancer", new Pulumi.Aws.LB.LoadBalancerArgs
        {
            Internal       = false,
            SecurityGroups =
            {
                group.Id
            },
            Subnets          = subnetIds,
            LoadBalancerType = "application",
        });

        this.Url = loadbalancer.DnsName;

        var targetGroup = new Pulumi.Aws.LB.TargetGroup("target-group", new Pulumi.Aws.LB.TargetGroupArgs
        {
            Port       = 80,
            Protocol   = "HTTP",
            TargetType = "ip",
            VpcId      = vpcId,
        });

        var listener = new Pulumi.Aws.LB.Listener("listener", new Pulumi.Aws.LB.ListenerArgs
        {
            LoadBalancerArn = loadbalancer.Arn,
            Port            = 80,
            DefaultActions  =
            {
                new Pulumi.Aws.LB.Inputs.ListenerDefaultActionsArgs
                {
                    Type           = "forward",
                    TargetGroupArn = targetGroup.Arn,
                }
            }
        });

        var userData = @"
#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
";

        var azs = Pulumi.Aws.GetAvailabilityZones.InvokeAsync(new Pulumi.Aws.GetAvailabilityZonesArgs()).Result;

        foreach (var az in azs.Names)
        {
            var server = new Pulumi.Aws.Ec2.Instance($"web-server-{az}", new Pulumi.Aws.Ec2.InstanceArgs
            {
                InstanceType        = "t2.micro",
                VpcSecurityGroupIds = { group.Id },
                UserData            = userData,
                Ami = ami.Apply(a => a.Id),
                AvailabilityZone = az,
            });

            var attachment = new Pulumi.Aws.LB.TargetGroupAttachment($"web-server-{az}", new Pulumi.Aws.LB.TargetGroupAttachmentArgs
            {
                Port           = 80,
                TargetGroupArn = targetGroup.Arn,
                TargetId       = server.PrivateIp,
            });
        }
    }
Exemplo n.º 11
0
    public MyStack()
    {
        var ami = Output.Create(Pulumi.Aws.GetAmi.InvokeAsync(new Pulumi.Aws.GetAmiArgs
        {
            MostRecent = true,
            Owners     = { "137112412989" },
            Filters    = { new Pulumi.Aws.Inputs.GetAmiFiltersArgs
                           {
                               Name = "name", Values = { "amzn-ami-hvm-*" }
                           } }
        }));

        var group = new Pulumi.Aws.Ec2.SecurityGroup("web-secgrp", new Pulumi.Aws.Ec2.SecurityGroupArgs
        {
            Description = "Enable HTTP access",
            Ingress     =
            {
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "tcp",
                    FromPort   = 80,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                },
                new Pulumi.Aws.Ec2.Inputs.SecurityGroupIngressArgs
                {
                    Protocol   = "icmp",
                    FromPort   = 8,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                }
            }
        });

        var userData = @"
#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
";

        var azs       = Pulumi.Aws.GetAvailabilityZones.InvokeAsync(new Pulumi.Aws.GetAvailabilityZonesArgs()).Result;
        var hostnames = new List <Input <string> >();
        var ips       = new List <Input <string> >();

        foreach (var az in azs.Names)
        {
            var server = new Pulumi.Aws.Ec2.Instance($"web-server-{az}", new Pulumi.Aws.Ec2.InstanceArgs
            {
                InstanceType        = "t2.micro",
                VpcSecurityGroupIds = { group.Id },
                UserData            = userData,
                Ami = ami.Apply(a => a.Id),
                AvailabilityZone = az,
            });

            hostnames.Add(server.PublicDns);
            ips.Add(server.PublicIp);
        }

        this.PublicIps = Output.All(ips.ToImmutableArray());
        this.PublicDns = Output.All(hostnames.ToImmutableArray());
    }