Sha256: 5f1d6f803f7def6699fd65cc9a21ea5e658715ae0cf2e3944fd7c95d764b28a0
Contents?: true
Size: 1.71 KB
Versions: 14
Compression:
Stored size: 1.71 KB
Contents
description 'Example stack template for a small EC2 instance' # NOTE: This template depends on vpc.rb # You can use the `include_template` function to include other ruby files into this Cloudformation template. include_template 'common/instance_deps.rb' # We can define extensions to resources, which extend the basic JSON-building # functionality of Cfer. Cfer provides a few of these, but you're free # to define your own by using `Cfer::Core::Resource.extend_resource` and specifying a # CloudFormation resource type. Inside the block, define any methods you'd like to use: Cfer::Core::Resource.extend_resource "AWS::EC2::Instance" do def boot_script(data) # This function simply wraps a bash script in the little bit of extra # sugar (hashbang + base64 encoding) that EC2 requires for userdata boot scripts. # See the AWS docs here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html script = <<-EOS.strip_heredoc #!/bin/bash #{data} EOS user_data Base64.encode64(script) end end resource :instance, "AWS::EC2::Instance" do # Using the extension defined above, we can have the instance write a simple # file to show that it's working. When you converge this template, there # should be a `welcome.txt` file sitting in the `ubuntu` user's home directory. boot_script "echo 'Welcome to Cfer!' > /home/ubuntu/welcome.txt" image_id Fn::ref(:ImageId) instance_type Fn::ref(:InstanceType) key_name Fn::ref(:KeyName) network_interfaces [ { AssociatePublicIpAddress: "true", DeviceIndex: "0", GroupSet: [ Fn::ref(:instancesg) ], SubnetId: Fn::ref(:SubnetId) } ] end output :instance, Fn::ref(:instance) output :instanceip, Fn::get_att(:instance, :PublicIp)
Version data entries
14 entries across 14 versions & 1 rubygems