Skip to content

Commit

Permalink
Merge pull request #654 from degica/nat-imdsv2
Browse files Browse the repository at this point in the history
Fix barcelona bootstrap
  • Loading branch information
kenta-s authored Feb 18, 2021
2 parents 6de4aa4 + 908819a commit 2977e75
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/barcelona/network/nat_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def build_resources
]
end

add_resource("AWS::EC2::LaunchTemplate", nat_launch_template_name) do |j|
j.LaunchTemplateName nat_launch_template_name
j.LaunchTemplateData do |d|
d.MetadataOptions do |m|
m.HttpTokens 'required'
end
end
end

add_resource("AWS::EC2::Instance", nat_name,
depends_on: ["VPCGatewayAttachment"]) do |j|
j.InstanceType options[:instance_type] || 't3.nano'
Expand All @@ -53,8 +62,9 @@ def build_resources
"GroupSet" => [ref("SecurityGroupNAT")]
}
]
j.MetadataOptions do |m|
m.HttpTokens 'required'
j.LaunchTemplate do |t|
t.LaunchTemplateName nat_launch_template_name
t.Version get_attr(nat_launch_template_name, "LatestVersionNumber")
end
j.Tags [
tag("barcelona", stack.district.name),
Expand Down Expand Up @@ -98,6 +108,10 @@ def eip_name
def nat_name
"NAT#{options[:type].to_s.classify}#{options[:nat_id]}"
end

def nat_launch_template_name
"NAT#{options[:type].to_s.classify}#{options[:nat_id]}LaunchTemplate"
end
end
end
end
7 changes: 6 additions & 1 deletion lib/tasks/bootstrap.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace :bcn do
end
end

def secret_key_base
ENV["SECRET_KEY_BASE"] || SecureRandom.hex(64)
end

desc "Deploy Barcelona to the specified ECS cluster(local)"
task :bootstrap => ["db:setup", :environment] do
access_key_id = ENV["AWS_ACCESS_KEY_ID"]
Expand Down Expand Up @@ -64,6 +68,7 @@ namespace :bcn do
image_tag: "master"
)
heritage.env_vars.build(key: "DATABASE_URL", value: ENV["BOOTSTRAP_DATABASE_URL"], secret: true)
heritage.env_vars.build(key: "SECRET_KEY_BASE", value: secret_key_base, secret: true)
heritage.env_vars.build(key: "DISABLE_DATABASE_ENVIRONMENT_CHECK", value: "1", secret: false)
heritage.env_vars.build(key: "AWS_REGION", value: region, secret: false)
heritage.env_vars.build(key: "AWS_ACCESS_KEY_ID", value: access_key_id, secret: false)
Expand Down Expand Up @@ -142,7 +147,7 @@ EOS
{key: "RAILS_LOG_TO_STDOUT", value: "true", secret: false},
{key: "GITHUB_ORGANIZATION", value: ENV['GITHUB_ORGANIZATION'], secret: false},
{key: "DATABASE_URL", value: ENV["DATABASE_URL"], secret: true},
{key: "SECRET_KEY_BASE", value: SecureRandom.hex(64), secret: true},
{key: "SECRET_KEY_BASE", value: secret_key_base, secret: true},
{key: "ENCRYPTION_KEY", value: ENV["ENCRYPTION_KEY"], secret: true}
],
services_attributes: [
Expand Down

0 comments on commit 2977e75

Please sign in to comment.