Created
September 5, 2023 06:17
-
-
Save shimoju/e0d13c4215132781c8c54258decf82f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
heroku_app_name = ARGV[0] | |
ssm_path = ARGV[1] | |
profile = 'oneaws-suzuri' | |
region = 'ap-northeast-1' | |
if heroku_app_name.nil? || ssm_path.nil? | |
raise ArgumentError, 'Usage: heroku-to-ssm <heroku_app_name> <ssm_path>' | |
end | |
unless ssm_path.start_with?('/') | |
raise ArgumentError, 'ssm_path must start with /' | |
end | |
json = `heroku config -a #{heroku_app_name} --json` | |
env_vars = JSON.parse(json) | |
env_vars.each do |k, v| | |
if k.start_with?('HEROKU_') | |
puts "Skip #{k}" | |
next | |
end | |
name = File.join(ssm_path, k) | |
puts "Put #{name}" | |
puts `aws ssm put-parameter --name '#{name}' --value '#{v}' --type String --profile '#{profile}' --region '#{region}'` | |
end | |
puts 'Finish!' | |
puts `aws ssm describe-parameters --parameter-filters 'Key=Name,Option=BeginsWith,Values=#{ssm_path}/' --profile '#{profile}' --region '#{region}' --output yaml` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sandboxで実行