コード例 #1
0
ファイル: Server.py プロジェクト: dechiad1/pulumi-aws-pave
def _get_ami():
    ami = aws.get_ami(most_recent=True,
                      owners=["amazon"],
                      filters=[{
                          "name": "name",
                          "values": ["amzn-ami-hvm-*"]
                      }])
    return ami.id
コード例 #2
0
ファイル: ec2.py プロジェクト: son-la/pulumi-experiment
def init():
    ami = aws.get_ami(filters=[
        {
            "name": "name",
            "values":
            ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"],
        },
        {
            "name": "virtualization-type",
            "values": ["hvm"],
        },
    ],
                      most_recent=True,
                      owners=["099720109477"])

    ec2_instance = aws.ec2.Instance("dev-machine",
                                    ami=ami.id,
                                    instance_type="t3.micro",
                                    tags={
                                        "provision": "pulumi",
                                        "stage": pulumi.get_stack(),
                                        "project": "webserver"
                                    })
コード例 #3
0
ファイル: __main__.py プロジェクト: kevanpeters/Intro_pulumi
import pulumi
import pulumi_aws as aws

sg = aws.ec2.SecurityGroup("web-sg",
                           description="Web sg for HTTP",
                           ingress=[{
                               'protocol': 'tcp',
                               'from_port': 80,
                               'to_port': 80,
                               'cidr_blocks': ['0.0.0.0/0']
                           }])

ami = aws.get_ami(most_recent="true",
                  owners=['amazon'],
                  filters=[{
                      'name': 'name',
                      'values': ['amzn-ami-hvm-*']
                  }])

user_data = """
#!/bin/bash
uname -n > index.html
nohup python -m SimpleHTTPServer 80 &
"""

instance = aws.ec2.Instance(
    "pulumi-webapp",
    instance_type="t2.micro",
    security_groups=[sg.name],
    ami=ami.id,
    user_data=user_data,
コード例 #4
0
ファイル: __main__.py プロジェクト: Hemanthkolli/pulumi-aws
"""A Python Pulumi program"""

import pulumi
import pulumi_aws as aws

size = 't2.micro'

ami = aws.get_ami(
    most_recent=True,
    owners=["137112412989"],
    filters=[aws.GetAmiFilterArgs(name="name", values=["amzn-ami-hvm-*"])])

group = aws.ec2.SecurityGroup('web-secgrp',
                              description='Enable HTTP access',
                              ingress=[
                                  aws.ec2.SecurityGroupIngressArgs(
                                      protocol='tcp',
                                      from_port=80,
                                      to_port=80,
                                      cidr_blocks=['0.0.0.0/0'],
                                  )
                              ])

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

server = aws.ec2.Instance('web-server-www',
                          instance_type=size,
コード例 #5
0
ファイル: __main__.base.py プロジェクト: alaksej/tf2pulumi
import pulumi
import pulumi_aws as aws

ubuntu = aws.get_ami(filters=[
    aws.GetAmiFilterArgs(
        name="name",
        values=["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"],
    ),
    aws.GetAmiFilterArgs(
        name="virtualization-type",
        values=["hvm"],
    ),
],
                     most_recent=True,
                     owners=["099720109477"])
web = aws.ec2.Instance("web",
                       ami=ubuntu.id,
                       instance_type="t2.micro",
                       tags={
                           "Name": "HelloWorld",
                       })
コード例 #6
0
import pulumi
import pulumi_aws as aws

ami = aws.get_ami(filters=[{
    "name": "name",
    "values": ["amzn-ami-hvm-*"],
}],
                  most_recent=True,
                  owners=["amazon"])
instance = aws.ec2.Instance("instance",
                            ami=ami.id,
                            instance_type="t2.micro",
                            tags={
                                "type": "test-instance",
                            })
sg = aws.ec2.SecurityGroup("sg", tags={
    "type": "test-security-group",
})
sg_attachment = aws.ec2.NetworkInterfaceSecurityGroupAttachment(
    "sgAttachment",
    network_interface_id=instance.primary_network_interface_id,
    security_group_id=sg.id)
コード例 #7
0
ファイル: __main__.py プロジェクト: jinwoov/IaC
import pulumi
import pulumi_aws as aws

ami = aws.get_ami(
    most_recent="true",
    owners=["137112412989"],  # aws temp
    filters=[{
        "name": "name",
        "values": ["amzn-ami-hvm-*-x86_64-ebs"]
    }])

group = aws.ec2.SecurityGroup("web-security group",
                              description='Enable HTTP access',
                              ingress=[{
                                  'protocol': 'icmp',
                                  'from_port': 8,
                                  'to_port': 0,
                                  'cidr_blocks': ['0.0.0.0/0']
                              }, {
                                  'protocol': 'tcp',
                                  'from_port': 80,
                                  'to_port': 80,
                                  'cidr_blocks': ['0.0.0.0/0']
                              }],
                              egress=[{
                                  'protocol': 'tcp',
                                  'from_port': 80,
                                  'to_port': 80,
                                  'cidr_blocks': ['0.0.0.0/0']
                              }])
コード例 #8
0
import pulumi
import pulumi_aws as aws

example = aws.get_ami(executable_users=["self"],
                      filters=[
                          {
                              "name": "name",
                              "values": ["myami-*"],
                          },
                          {
                              "name": "root-device-type",
                              "values": ["ebs"],
                          },
                          {
                              "name": "virtualization-type",
                              "values": ["hvm"],
                          },
                      ],
                      most_recent=True,
                      name_regex="^myami-\\d{3}",
                      owners=["self"])
コード例 #9
0
ファイル: snippets.py プロジェクト: karlkeppner1/snippets
    },  # dict – Configuration block with remote access settings. Detailed below.
    scaling_config={
        'desiredSize': 2,
        'max_size': 3,
        'min_size': 1
    },  # dict – Configuration block with scaling settings. Detailed below. REQUIRED
    subnet_ids=
    None,  # list – Identifiers of EC2 Subnets to associate with the EKS Node Group. These subnets must have the following resource tag: kubernetes.io/cluster/CLUSTER_NAME (where CLUSTER_NAME is replaced with the name of the EKS Cluster). REQUIRED
    tags=None,  # dict – Key-value mapping of resource tags.
    version=
    None  # str - Kubernetes version. Defaults to EKS Cluster Kubernetes version. Will only perform drift detection if a configuration value is provided.
)

ami = aws.get_ami(most_recent="true",
                  owners=["137112412989"],
                  filters=[{
                      "name": "name",
                      "values": ["amzn2-ami-hvm-*"]
                  }])

dns_record = aws.route53.Record(
    'resource_name',  # str – The name of the resource.
    opts=
    None,  # https://www.pulumi.com/docs/reference/pkg/python/pulumi/#pulumi.ResourceOptions
    aliases=
    None,  # list – An alias block. Conflicts with ttl & records. Alias record documented below.
    allow_overwrite=
    None,  # bool – Allow creation of this record to overwrite an existing record, if any. This does not affect the ability to update the record using this provider and does not prevent other resources within this provider or manual Route 53 changes outside this provider from overwriting this record. false by default. This configuration is not recommended for most environments.
    failover_routing_policies=
    None,  # list – A block indicating the routing behavior when associated health check fails. Conflicts with any other routing policy. Documented below.
    geolocation_routing_policies=
    None,  # list – A block indicating a routing policy based on the geolocation of the requestor. Conflicts with any other routing policy. Documented below.
コード例 #10
0
node_chain = config.require("node_chain")
ssh_public_key = config.require("ssh_public_key")
stack_name = pulumi.get_stack()

# setting ssh key
ssh_key = aws.ec2.KeyPair("pulumi01", public_key=ssh_public_key)

# choosing the latest ubuntu minimal 20.04 image
ubuntu_minimal = aws.get_ami(
    most_recent=True,
    filters=[
        aws.GetAmiFilterArgs(
            name="name",
            values=[
                "ubuntu-minimal/images/hvm-ssd/ubuntu-focal-20.04-amd64-minimal*"
            ],
        ),
        aws.GetAmiFilterArgs(
            name="virtualization-type",
            values=["hvm"],
        ),
    ],
    owners=["099720109477"])

security_group = aws.ec2.SecurityGroup('ssh and node public access',
                                       description='Enable SSH + node access',
                                       egress=[
                                           {
                                               'protocol': '-1',
                                               'fromPort': 0,
                                               'toPort': 0,
コード例 #11
0
private_key_passphrase = config.get_secret('privateKeyPassphrase')

# Create a new security group that permits SSH and web access.
secgrp = aws.ec2.SecurityGroup('secgrp',
    description='Foo',
    ingress=[
        { 'protocol': 'tcp', 'from_port': 22, 'to_port': 22, 'cidr_blocks': ['0.0.0.0/0'] },
        { 'protocol': 'tcp', 'from_port': 80, 'to_port': 80, 'cidr_blocks': ['0.0.0.0/0'] },
    ],
)

# Get the AMI
ami = aws.get_ami(
    owners=['amazon'],
    most_recent=True,
    filters=[{
        'name': 'name',
        'values': ['amzn2-ami-hvm-2.0.????????-x86_64-gp2'],
    }],
)

# Create an EC2 server that we'll then provision stuff onto.
size = 't2.micro'
if key_name is None:
    key = aws.ec2.KeyPair('key', public_key=public_key)
    key_name = key.key_name
server = aws.ec2.Instance('server',
    instance_type=size,
    ami=ami.id,
    key_name=key_name,
    vpc_security_group_ids=[ secgrp.id ],
)
コード例 #12
0
ファイル: EKS.py プロジェクト: dechiad1/pulumi-aws-pave
def _get_eks_ami(version):
    # remove the Patch from the version - its not used in AMI ids
    major_minor = ".".join(version.split('.')[:2])
    eks_node_version = "amazon-eks-node-%s-v*" % major_minor
    ami = pulumi_aws.get_ami(most_recent=True, owners=["amazon"], filters=[{"name": "name", "values" :[eks_node_version]}])
    return ami.id
コード例 #13
0
import pulumi
import pulumi_aws as aws
from pulumi_aws import ec2

# AMI image configuration
ec2_image_id = 'ami-07d1bb89ff2dd50fe'
ec2_image_owner = '099720109477'
ec2_instance_size = 't2.micro'
ec2_instance_name = 'aws-ec2-ubuntu'
ec2_keypair_name = 'pulumi_key'
ec2_ssh_port = 22

# Lets use Pulumi to get the AMI image
pulumi_ami = aws.get_ami(filters=[{
    "name": "image-id",
    "values": [ec2_image_id]
}],
                         owners=[ec2_image_owner])

# Create a EC2 security group
pulumi_security_group = ec2.SecurityGroup(
    'pulumi-secgrp',
    description='pulumi: enable SSH access & outgoing connections',
    ingress=[{
        'protocol': 'tcp',
        'from_port': ec2_ssh_port,
        'to_port': ec2_ssh_port,
        'cidr_blocks': ['0.0.0.0/0']
    }],
    egress=[{
        'protocol': '-1',
コード例 #14
0
import pulumi
import pulumi_aws as aws

instance_type = 't2.micro'
ebs_size = 10 #in GiBs
az = "eu-central-1a"

ami = aws.get_ami(most_recent="true",
                  owners=["amazon"] ,
                  filters=[
                      {"name":"owner-alias","values":["amazon"]},
                      {"name": "name", "values":["amzn2-ami-hvm*"]}
                  ])

sg = aws.ec2.SecurityGroup('zookeeper-sg',
    description='Allow Zookeeper traffic',
    ingress=[
        { 'protocol': 'tcp',
          'from_port': 22,
          'to_port': 22,
          'cidr_blocks': ['0.0.0.0/0']
        },
        { 'protocol': 'tcp',
          'from_port': 2181,
          'to_port': 2181,
          'cidr_blocks': ['0.0.0.0/0']
        }
    ],
    egress=[
        { 'protocol': -1, 
          'from_port': 0,
コード例 #15
0
ファイル: __main__.py プロジェクト: gordonmurray/learn_sysops
# Define some variables to use in the stack
size = "t2.micro"
vpc_id = "vpc-xxxxxx"
subnet_id = "subnet-xxxxxx"
public_key = "ssh-rsa xxxxxxxxxxx"
user_data = """#!/bin/bash
sudo apt update
sudo apt install apache2 -y
echo 'Hello World!' > /var/www/html/index.html"""

# Get the AMI ID of the latest Ubuntu 18.04 version from Canonical
ami = aws.get_ami(
    most_recent="true",
    owners=["099720109477"],
    filters=[
        {
            "name": "name",
            "values": ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"],
        }
    ],
)

# Create an AWS Key Pair
keypair = aws.ec2.KeyPair(
    "keypair-pulumi",
    key_name="keypair-pulumi",
    public_key=public_key,
    tags={"Name": "keypair-pulumi"},
)

# Create an AWS Security group with ingress and egress rules
group = aws.ec2.SecurityGroup(
コード例 #16
0
import pulumi_aws
from vpc_setup import shared_vpc, availableZones, subnet_application

ami=pulumi_aws.get_ami(filters=[
                {
                    "name": "name",
                    "values": ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"],
                },
                {
                    "name": "virtualization-type",
                    "values": ["hvm"],
                },
            ],
            most_recent=True,
            owners=["099720109477"])

ec2SecurityGroup = pulumi_aws.ec2.SecurityGroup(
    resource_name="pulumi-aws-example_application",
    vpc_id=shared_vpc.id,
    egress=[{
        'from_port' : '0',
        'to_port' : '0',
        'protocol' : '-1',
        'cidr_blocks' : ['0.0.0.0/0']
    }],
    ingress=[{
            'cidr_blocks' : ['0.0.0.0/0'],
            'from_port' : '80',
            'to_port' : '80',
            'protocol' : 'tcp',
            'description' : 'Allow internet access to instance'
コード例 #17
0
ファイル: __main__.py プロジェクト: devang-s/pulumi-project
import pulumi
import pulumi_aws as _aws

sg = _aws.ec2.SecurityGroup("web-app-sg",
                            description='Enable HTTP access',
                            ingress=[{
                                'protocol': 'tcp',
                                'from_port': 80,
                                'to_port': 80,
                                'cidr_blocks': ['0.0.0.0/0']
                            }])

ami = _aws.get_ami(most_recent="true",
                   owners=["amazon"],
                   filters=[{
                       "name": "name",
                       "values": ["amzn-ami-hvm-*"]
                   }])

user_data = """
#!bin/bash
uname -n > index.html
nohup python -m SimpleHTTPServer 80 &
"""

instance = _aws.ec2.Instance("my-web-app",
                             instance_type="t2.micro",
                             security_groups=[sg.name],
                             ami=ami.id,
                             user_data=user_data)
コード例 #18
0
ファイル: infra.py プロジェクト: rmulder/pulumi-aws-examples
import pulumi
from pulumi_aws import ec2, get_ami, GetAmiFilterArgs

group = ec2.SecurityGroup('web-secgrp', ingress=[
    # Uncomment to fail a test:
    #{ "protocol": "tcp", "from_port": 22, "to_port": 22, "cidr_blocks": ["0.0.0.0/0"] },
    { "protocol": "tcp", "from_port": 80, "to_port": 80, "cidr_blocks": ["0.0.0.0/0"] },
])

user_data = '#!/bin/bash echo "Hello, World!" > index.html nohup python -m SimpleHTTPServer 80 &'

ami_id = get_ami(
    most_recent=True,
    owners=["099720109477"],
    filters=[
        GetAmiFilterArgs(
            name="name",
            values=["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
        )]
).id

server = ec2.Instance('web-server-www',
    instance_type="t2.micro",
    vpc_security_group_ids=[ group.id ], # reference the group object above
    # Comment out to fail a test:
    tags={'Name': 'webserver'},          # name tag
    # Uncomment to fail a test:
    #user_data=user_data)                # start a simple web server
    ami=ami_id)
コード例 #19
0
ファイル: aws-webserver.pp.py プロジェクト: sadpdtchr/pulumi
import pulumi
import pulumi_aws as aws

# Create a new security group for port 80.
security_group = aws.ec2.SecurityGroup("securityGroup",
                                       ingress=[{
                                           "protocol": "tcp",
                                           "fromPort": 0,
                                           "toPort": 0,
                                           "cidrBlocks": ["0.0.0.0/0"],
                                       }])
ami = aws.get_ami(filters=[{
    "name": "name",
    "values": ["amzn-ami-hvm-*-x86_64-ebs"],
}],
                  owners=["137112412989"],
                  most_recent=True)
# Create a simple web server using the startup script for the instance.
server = aws.ec2.Instance("server",
                          tags={
                              "Name": "web-server-www",
                          },
                          instance_type="t2.micro",
                          security_groups=[security_group.name],
                          ami=ami.id,
                          user_data="""#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &
""")
pulumi.export("publicIp", server.public_ip)
pulumi.export("publicHostName", server.public_dns)
コード例 #20
0
                                         from_port=22,
                                         to_port=22,
                                         cidr_blocks=['0.0.0.0/0']),
        aws.ec2.SecurityGroupIngressArgs(protocol='tcp',
                                         from_port=80,
                                         to_port=80,
                                         cidr_blocks=['0.0.0.0/0']),
    ],
)

# Get the AMI
ami = aws.get_ami(
    owners=['amazon'],
    most_recent=True,
    filters=[
        aws.GetAmiFilterArgs(
            name='name',
            values=['amzn2-ami-hvm-2.0.????????-x86_64-gp2'],
        )
    ],
)

# Create an EC2 server that we'll then provision stuff onto.
size = 't2.micro'
if key_name is None:
    key = aws.ec2.KeyPair('key', public_key=public_key)
    key_name = key.key_name
server = aws.ec2.Instance(
    'server',
    instance_type=size,
    ami=ami.id,
    key_name=key_name,
コード例 #21
0
import pulumi_aws as aws

# Create a new security group for port 80.
security_group = aws.ec2.SecurityGroup("securityGroup",
                                       ingress=[
                                           aws.ec2.SecurityGroupIngressArgs(
                                               protocol="tcp",
                                               from_port=0,
                                               to_port=0,
                                               cidr_blocks=["0.0.0.0/0"],
                                           )
                                       ])
ami = aws.get_ami(filters=[
    aws.GetAmiFilterArgs(
        name="name",
        values=["amzn-ami-hvm-*-x86_64-ebs"],
    )
],
                  owners=["137112412989"],
                  most_recent=True)
# Create a simple web server using the startup script for the instance.
server = aws.ec2.Instance("server",
                          tags={
                              "Name": "web-server-www",
                          },
                          instance_type="t2.micro",
                          security_groups=[security_group.name],
                          ami=ami.id,
                          user_data="""#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &
""")
コード例 #22
0
import pulumi
import pulumi_aws as aws

# Create a new security group for port 80.
security_group = aws.ec2.SecurityGroup("securityGroup",
                                       ingress=[{
                                           "protocol": "tcp",
                                           "fromPort": 0,
                                           "toPort": 0,
                                           "cidrBlocks": ["0.0.0.0/0"],
                                       }])
ami = aws.get_ami({
    "filters": [{
        "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.
server = aws.ec2.Instance("server",
                          tags={
                              "Name": "web-server-www",
                          },
                          instance_type="t2.micro",
                          security_groups=[security_group.name],
                          ami=ami.id,
                          user_data=f"""#!/bin/bash
echo \"Hello, World!\" > index.html
nohup python -m SimpleHTTPServer 80 &
コード例 #23
0
        }],
    }),
)
ecs_instance_role_policy_attach = aws.iam.RolePolicyAttachment(
    "ecs-instance-policy-attach",
    role=ecs_instance_role.name,
    policy_arn=
    "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role")
ecs_instance_profile = aws.iam.InstanceProfile("ecs-iam-instance-profile",
                                               role=ecs_instance_role.name)

# Find an "ECS optimized" AMI to use for the EC2 container instances.
ecs_instance_ami = aws.get_ami(most_recent="true",
                               owners=["amazon"],
                               filters=[{
                                   "name":
                                   "name",
                                   "values": ["amzn2-ami-ecs-hvm-*-x86_64-*"]
                               }])

# User-data so the EC2 container instance will connect to the created cluster.
cluster_name = "my-fancy-new-ecs-cluster"
user_data = '''#!/bin/bash
echo ECS_CLUSTER={cluster_nm} >> /etc/ecs/ecs.config'''.format(
    cluster_nm=cluster_name)

# create launch configuration
launch_config = aws.ec2.LaunchConfiguration(
    "launch-config",
    image_id=ecs_instance_ami.id,
    instance_type="t2.micro",