示例#1
0
# Copyright 2016-2018, Pulumi Corporation.  All rights reserved.

import pulumi
from pulumi_aws import ec2
from ami import get_linux_ami

size = 't2.micro'

group = ec2.SecurityGroup('web-secgrp',
                          description='Enable HTTP access',
                          ingress=[{
                              'protocol': 'tcp',
                              'from_port': 80,
                              'to_port': 80,
                              'cidr_blocks': ['0.0.0.0/0']
                          }])
server = ec2.Instance('web-server-www',
                      instance_type=size,
                      security_groups=[group.name],
                      ami=get_linux_ami(size))

pulumi.export('public_ip', server.public_ip)
pulumi.export('public_dns', server.public_dns)
示例#2
0
# Use the default environment
env = SecretsEnvironment()
env.read_secrets()
aws_private_keypath = env.get_secret('aws_privatekey_path')
with open(aws_private_keypath + '.pub', 'r') as f:
    aws_publickey = f.read().strip()

instance_type = env.get_secret('aws_instance_type')
pulumi.info(msg="instance_type={}".format(instance_type))
try:
    ami = env.get_secret('aws_ami_id')
except RuntimeError:
    ami = ''
if ami == '':
    ami = get_linux_ami(instance_type)
pulumi.info(msg="ami={}".format(ami))

web_group = ec2.SecurityGroup('web-secgrp',
                              description='Enable HTTP/HTTPS access',
                              ingress=[{
                                  'protocol': 'tcp',
                                  'from_port': 80,
                                  'to_port': 80,
                                  'cidr_blocks': ['0.0.0.0/0']
                              }, {
                                  'protocol': 'tcp',
                                  'from_port': 443,
                                  'to_port': 443,
                                  'cidr_blocks': ['0.0.0.0/0']
                              }],