Esempio n. 1
0
def addSearchGuard(template, role, subnet, keyname, secgroup, profilename):
    profile = InstanceProfile("sgprofile" + profilename,
                              Path="/",
                              Roles=[Ref(role)])
    template.add_resource(profile)
    instance = Instance(
        "sg" + profilename,
        InstanceType="m4.xlarge",
        ImageId=FindInMap("RegionToAmi", Ref("AWS::Region"), "stable"),
        DisableApiTermination=False,
        IamInstanceProfile=Ref(profile),
        KeyName=Ref(keyname),
        Monitoring=False,
        InstanceInitiatedShutdownBehavior="stop",
        UserData=userdata.from_file("src/bootstrap.sh"),
        NetworkInterfaces=[
            NetworkInterfaceProperty(DeviceIndex=0,
                                     Description="Primary network interface",
                                     SubnetId=Ref(subnet),
                                     DeleteOnTermination=True,
                                     AssociatePublicIpAddress=True,
                                     GroupSet=[Ref(secgroup)])
        ],
        Tags=[
            Tag("Name", "Search Guard " + profilename),
            Tag("sgnodetag", profilename)
        ],
        EbsOptimized=False,
        BlockDeviceMappings=[
            BlockDeviceMapping(DeviceName="/dev/sda1",
                               Ebs=EBSBlockDevice(VolumeSize=25))
        ])
    template.add_resource(instance)
    return instance
Esempio n. 2
0
 def create_result(self, file, delimiter=""):
     file = os.path.join(self.filepath, file)
     self.instance.UserData = userdata.from_file(file, delimiter)
     return self.instance.UserData.to_dict()
Esempio n. 3
0
from troposphere import Template
from troposphere.helpers import userdata
import troposphere.ec2 as ec2

t = Template()
t.add_resource(
    ec2.Instance(
        'Ec2Instance',
        ImageId='ami-16fd7026',
        InstanceType='t3.nano',
        KeyName='mykey',
        UserData=userdata.from_file('userdata.sh'),
    ))

print(t.to_yaml())
Esempio n. 4
0
 def create_result(self, file, delimiter=""):
     file = os.path.join(self.filepath, file)
     self.instance.UserData = userdata.from_file(file, delimiter)
     return json.dumps(self.instance.UserData, cls=awsencode)
Esempio n. 5
0
 def create_result(self, file, delimiter=""):
     file = os.path.join(self.filepath, file)
     self.instance.UserData = userdata.from_file(file, delimiter)
     return json.dumps(self.instance.UserData, cls=awsencode)
Esempio n. 6
0
                                        Effect="Allow")
                                ]))
             ]))

instance_profile = template.add_resource(
    iam.InstanceProfile("InstanceProfile", Path="/", Roles=[Ref(role)]))

launch_configuration = template.add_resource(
    asc.LaunchConfiguration("LaunchConfiguration",
                            ImageId=Ref(image),
                            SecurityGroups=[Ref(security_group)],
                            InstanceMonitoring=False,
                            IamInstanceProfile=Ref(instance_profile),
                            InstanceType=Ref(instance_type),
                            KeyName=Ref(ssh_key_name),
                            UserData=from_file("out/cloud-config.yaml"),
                            AssociatePublicIpAddress=True))

autoscaling_group = template.add_resource(
    asc.AutoScalingGroup(
        "AutoScalingGroup",
        DependsOn=["PublicRoute"],
        AvailabilityZones=[Ref(availability_zone_1),
                           Ref(availability_zone_2)],
        VPCZoneIdentifier=[Ref(subnet_1), Ref(subnet_2)],
        LaunchConfigurationName=Ref(launch_configuration),
        MinSize=0,
        MaxSize=1,
        DesiredCapacity=1,
        Tags=asc.Tags(Name="euca.me")))
Esempio n. 7
0
 def create_result(self, file, delimiter=""):
     file = os.path.join(self.filepath, file)
     self.instance.UserData = userdata.from_file(file, delimiter)
     return self.instance.UserData.to_dict()