dh-proteus 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/dh-proteus.gemspec +0 -3
 - data/lib/proteus/app.rb +31 -0
 - data/lib/proteus/commands/state/list.rb +25 -0
 - data/lib/proteus/commands/state/move.rb +28 -0
 - data/lib/proteus/commands/state/remove.rb +71 -0
 - data/lib/proteus/commands/state/show.rb +25 -0
 - data/lib/proteus/commands/taint.rb +0 -2
 - data/lib/proteus/common.rb +9 -6
 - data/lib/proteus/config/config.rb +6 -0
 - data/lib/proteus/version.rb +1 -1
 - metadata +6 -46
 - data/lib/proteus/commands/move.rb +0 -28
 - data/lib/proteus/commands/remove.rb +0 -69
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b9166f710a73dd5e425c1c57678b074953e822f18373115dab83c2bb69c1a4e1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 536e2c89ea79aeb66cd751d280905bdad818d0f3dde221d8b6a8ed3714a1f16d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: addf02fb05acde3f7fbe087fb969725ea07ff5aa191ddb3a3025dbaf8b8abb6ead4b9a0639151698ae74f758ec05da7777f9d838c4361be933ff18e0fb2a2288
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0fc89209ad85a76df1010b7842b9a6ff427b9171b3e888ad5ff5cb2a4533d755f4d2070a7f6599af991ac20c5dfb9b056d8f1f135818dbfa0a4e655aa0c686ad
         
     | 
    
        data/dh-proteus.gemspec
    CHANGED
    
    | 
         @@ -43,7 +43,4 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       43 
43 
     | 
    
         
             
              spec.add_runtime_dependency 'activesupport', '~> 5.1.1'
         
     | 
| 
       44 
44 
     | 
    
         
             
              spec.add_runtime_dependency 'thor', '~> 0.20.0'
         
     | 
| 
       45 
45 
     | 
    
         
             
              spec.add_runtime_dependency 'erubis', '~> 2.7.0'
         
     | 
| 
       46 
     | 
    
         
            -
              spec.add_runtime_dependency 'aws-sdk-rds', '~> 1.11.0'
         
     | 
| 
       47 
     | 
    
         
            -
              spec.add_runtime_dependency 'aws-sdk-route53', '~> 1.7.0'
         
     | 
| 
       48 
     | 
    
         
            -
              spec.add_runtime_dependency 'aws-sdk-elasticsearchservice', '~> 1.4.0'
         
     | 
| 
       49 
46 
     | 
    
         
             
            end
         
     | 
    
        data/lib/proteus/app.rb
    CHANGED
    
    | 
         @@ -7,6 +7,10 @@ require 'proteus/context_management/context' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            require 'proteus/context_management/helpers'
         
     | 
| 
       8 
8 
     | 
    
         
             
            require 'proteus/templates/template_binding'
         
     | 
| 
       9 
9 
     | 
    
         
             
            require 'proteus/templates/partial'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'proteus/commands/state/list'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'proteus/commands/state/move'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'proteus/commands/state/remove'
         
     | 
| 
      
 13 
     | 
    
         
            +
            require 'proteus/commands/state/show'
         
     | 
| 
       10 
14 
     | 
    
         | 
| 
       11 
15 
     | 
    
         
             
            module Proteus
         
     | 
| 
       12 
16 
     | 
    
         | 
| 
         @@ -56,6 +60,33 @@ module Proteus 
     | 
|
| 
       56 
60 
     | 
    
         
             
                      def self.environment
         
     | 
| 
       57 
61 
     | 
    
         
             
                        @environment
         
     | 
| 
       58 
62 
     | 
    
         
             
                      end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                      state_class = Class.new(Proteus::Common)
         
     | 
| 
      
 65 
     | 
    
         
            +
                      state_class_name = "#{class_name}State"
         
     | 
| 
      
 66 
     | 
    
         
            +
                      mod_name.const_set(state_class_name, state_class)
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                      state_class.class_eval do
         
     | 
| 
      
 69 
     | 
    
         
            +
                        include Config
         
     | 
| 
      
 70 
     | 
    
         
            +
                        include Helpers
         
     | 
| 
      
 71 
     | 
    
         
            +
                        include Proteus::Helpers::PathHelpers
         
     | 
| 
      
 72 
     | 
    
         
            +
                        include Proteus::Commands::StateCommands::List
         
     | 
| 
      
 73 
     | 
    
         
            +
                        include Proteus::Commands::StateCommands::Move
         
     | 
| 
      
 74 
     | 
    
         
            +
                        include Proteus::Commands::StateCommands::Remove
         
     | 
| 
      
 75 
     | 
    
         
            +
                        include Proteus::Commands::StateCommands::Show
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                        private
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                        define_method :context do
         
     | 
| 
      
 80 
     | 
    
         
            +
                          context.name
         
     | 
| 
      
 81 
     | 
    
         
            +
                        end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                        define_method :environment do
         
     | 
| 
      
 84 
     | 
    
         
            +
                          environment
         
     | 
| 
      
 85 
     | 
    
         
            +
                        end
         
     | 
| 
      
 86 
     | 
    
         
            +
                      end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                      desc 'state', 'This command has subcommands for advanced state management.'
         
     | 
| 
      
 89 
     | 
    
         
            +
                      subcommand('state', state_class)
         
     | 
| 
       59 
90 
     | 
    
         
             
                    end
         
     | 
| 
       60 
91 
     | 
    
         | 
| 
       61 
92 
     | 
    
         
             
                    if context.name == 'default'
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Proteus
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Commands
         
     | 
| 
      
 3 
     | 
    
         
            +
                module StateCommands
         
     | 
| 
      
 4 
     | 
    
         
            +
                  module List
         
     | 
| 
      
 5 
     | 
    
         
            +
                    def self.included(thor_class)
         
     | 
| 
      
 6 
     | 
    
         
            +
                      thor_class.class_eval do
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                        desc "list", "List resources in the state"
         
     | 
| 
      
 9 
     | 
    
         
            +
                        def list
         
     | 
| 
      
 10 
     | 
    
         
            +
                          list_cmd = <<~LIST_CMD
         
     | 
| 
      
 11 
     | 
    
         
            +
                            cd #{context_path(context)} && \
         
     | 
| 
      
 12 
     | 
    
         
            +
                            terraform state list
         
     | 
| 
      
 13 
     | 
    
         
            +
                          LIST_CMD
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                          init(verbose: parent_options[:verbose])
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                          syscall list_cmd.squeeze(' ')
         
     | 
| 
      
 18 
     | 
    
         
            +
                        end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                      end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Proteus
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Commands
         
     | 
| 
      
 3 
     | 
    
         
            +
                module StateCommands
         
     | 
| 
      
 4 
     | 
    
         
            +
                  module Move
         
     | 
| 
      
 5 
     | 
    
         
            +
                    def self.included(thor_class)
         
     | 
| 
      
 6 
     | 
    
         
            +
                      thor_class.class_eval do
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                        desc "move FROM TO", "Moves an existing resource within the Terraform state"
         
     | 
| 
      
 9 
     | 
    
         
            +
                        def move(from, to)
         
     | 
| 
      
 10 
     | 
    
         
            +
                          init(verbose: parent_options[:verbose])
         
     | 
| 
      
 11 
     | 
    
         
            +
                          confirm question: "Do you really want to move #{from} to #{to} in context '(#{context}, #{environment})'?", color: :on_red, exit_code: 0 do
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                            state_move_command = <<~STATE_MOVE_COMMAND
         
     | 
| 
      
 14 
     | 
    
         
            +
                              cd #{context_path(context)} && \
         
     | 
| 
      
 15 
     | 
    
         
            +
                              terraform state mv \
         
     | 
| 
      
 16 
     | 
    
         
            +
                              #{from} \
         
     | 
| 
      
 17 
     | 
    
         
            +
                              #{to}
         
     | 
| 
      
 18 
     | 
    
         
            +
                            STATE_MOVE_COMMAND
         
     | 
| 
      
 19 
     | 
    
         
            +
                            syscall state_move_command.squeeze(' '), dryrun:  dryrun
         
     | 
| 
      
 20 
     | 
    
         
            +
                          end
         
     | 
| 
      
 21 
     | 
    
         
            +
                        end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                      end
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,71 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Proteus
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Commands
         
     | 
| 
      
 3 
     | 
    
         
            +
                module StateCommands
         
     | 
| 
      
 4 
     | 
    
         
            +
                  module Remove
         
     | 
| 
      
 5 
     | 
    
         
            +
                    def self.included(thor_class)
         
     | 
| 
      
 6 
     | 
    
         
            +
                      thor_class.class_eval do
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                        desc "remove", "Remove a resource from the terraform state"
         
     | 
| 
      
 9 
     | 
    
         
            +
                        long_desc <<-LONGDESC
         
     | 
| 
      
 10 
     | 
    
         
            +
                          Remove a resource from the terraform state
         
     | 
| 
      
 11 
     | 
    
         
            +
                          --bulk Enables bulk import mode
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                          --resource_address Terraform address of resource to remove from the terraform state
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                          --resources_file File containing resource addresses and identifiers
         
     | 
| 
      
 16 
     | 
    
         
            +
                        LONGDESC
         
     | 
| 
      
 17 
     | 
    
         
            +
                        option :bulk, type: :boolean, aliases: "-b", required: false, default: false
         
     | 
| 
      
 18 
     | 
    
         
            +
                        option :resource_address, type: :string, aliases: "-a", required: false, default: nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                        option :resources_file, type: :string, aliases: "-f", required: false, default: nil
         
     | 
| 
      
 20 
     | 
    
         
            +
                        def remove
         
     | 
| 
      
 21 
     | 
    
         
            +
                          if options[:bulk]
         
     | 
| 
      
 22 
     | 
    
         
            +
                            if !options[:resources_file]
         
     | 
| 
      
 23 
     | 
    
         
            +
                              say "Supply a file containing resource identifiers and Terraform addresses for bulk operations", :red
         
     | 
| 
      
 24 
     | 
    
         
            +
                              exit 1
         
     | 
| 
      
 25 
     | 
    
         
            +
                            end
         
     | 
| 
      
 26 
     | 
    
         
            +
                          else
         
     | 
| 
      
 27 
     | 
    
         
            +
                            if !options[:resource_address]
         
     | 
| 
      
 28 
     | 
    
         
            +
                              say "You need to supply a resource address.", :red
         
     | 
| 
      
 29 
     | 
    
         
            +
                              exit 1
         
     | 
| 
      
 30 
     | 
    
         
            +
                            end
         
     | 
| 
      
 31 
     | 
    
         
            +
                          end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                          init(verbose: parent_options[:verbose])
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                          confirm question: "Do you really want to run 'terraform state rm' in context '(#{context}, #{environment})'?", color: :on_red, exit_code: 0 do
         
     | 
| 
      
 36 
     | 
    
         
            +
                            state_remove_command = <<~STATE_REMOVE_COMMAND
         
     | 
| 
      
 37 
     | 
    
         
            +
                              cd #{context_path(context)} && \
         
     | 
| 
      
 38 
     | 
    
         
            +
                              terraform state rm \
         
     | 
| 
      
 39 
     | 
    
         
            +
                              %{resource_addresses}
         
     | 
| 
      
 40 
     | 
    
         
            +
                            STATE_REMOVE_COMMAND
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                            if options[:bulk]
         
     | 
| 
      
 43 
     | 
    
         
            +
                              if File.file?(options[:resources_file])
         
     | 
| 
      
 44 
     | 
    
         
            +
                                File.open(options[:resources_file], "r") do |file|
         
     | 
| 
      
 45 
     | 
    
         
            +
                                  resource_addresses = []
         
     | 
| 
      
 46 
     | 
    
         
            +
                                  file.each_line do |line|
         
     | 
| 
      
 47 
     | 
    
         
            +
                                    resource = line.chomp.split(" = ")
         
     | 
| 
      
 48 
     | 
    
         
            +
                                    resource_addresses << resource[0]
         
     | 
| 
      
 49 
     | 
    
         
            +
                                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                                  resource_addresses.each_slice(500) do |slice|
         
     | 
| 
      
 52 
     | 
    
         
            +
                                    syscall (state_remove_command % { resource_addresses: slice.join(' ') }).squeeze(' ')
         
     | 
| 
      
 53 
     | 
    
         
            +
                                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                                end
         
     | 
| 
      
 56 
     | 
    
         
            +
                              else
         
     | 
| 
      
 57 
     | 
    
         
            +
                                say "File #{options[:resources_file]} does not exist.", :red
         
     | 
| 
      
 58 
     | 
    
         
            +
                                exit 1
         
     | 
| 
      
 59 
     | 
    
         
            +
                              end
         
     | 
| 
      
 60 
     | 
    
         
            +
                            else
         
     | 
| 
      
 61 
     | 
    
         
            +
                              syscall (state_remove_command % { resource_addresses: options[:resource_address] })
         
     | 
| 
      
 62 
     | 
    
         
            +
                            end
         
     | 
| 
      
 63 
     | 
    
         
            +
                          end
         
     | 
| 
      
 64 
     | 
    
         
            +
                        end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                      end
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Proteus
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Commands
         
     | 
| 
      
 3 
     | 
    
         
            +
                module StateCommands
         
     | 
| 
      
 4 
     | 
    
         
            +
                  module Show
         
     | 
| 
      
 5 
     | 
    
         
            +
                    def self.included(thor_class)
         
     | 
| 
      
 6 
     | 
    
         
            +
                      thor_class.class_eval do
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                        desc "show", "Show a resource in the state"
         
     | 
| 
      
 9 
     | 
    
         
            +
                        def show(resource)
         
     | 
| 
      
 10 
     | 
    
         
            +
                          list_cmd = <<~LIST_CMD
         
     | 
| 
      
 11 
     | 
    
         
            +
                            cd #{context_path(context)} && \
         
     | 
| 
      
 12 
     | 
    
         
            +
                            terraform state show #{resource}
         
     | 
| 
      
 13 
     | 
    
         
            +
                          LIST_CMD
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                          init(verbose: parent_options[:verbose])
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                          syscall list_cmd.squeeze(' ')
         
     | 
| 
      
 18 
     | 
    
         
            +
                        end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                      end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -11,7 +11,6 @@ module Proteus 
     | 
|
| 
       11 
11 
     | 
    
         
             
                        --resource The resource to taint
         
     | 
| 
       12 
12 
     | 
    
         
             
                      LONGDESC
         
     | 
| 
       13 
13 
     | 
    
         
             
                      option :resource, type: :string, aliases: "-r", required: true
         
     | 
| 
       14 
     | 
    
         
            -
                      option :module, type: :string, aliases: "-m", required: false, default: nil
         
     | 
| 
       15 
14 
     | 
    
         
             
                      def taint
         
     | 
| 
       16 
15 
     | 
    
         
             
                        init(verbose: parent_options[:verbose])
         
     | 
| 
       17 
16 
     | 
    
         
             
                        confirm question: "Do you really want to run 'terraform taint' on environment '#{environment}' in context '#{context}'?", color: :on_red, exit_code: 0 do
         
     | 
| 
         @@ -19,7 +18,6 @@ module Proteus 
     | 
|
| 
       19 
18 
     | 
    
         
             
                          taint_command = <<~TAINT_COMMAND
         
     | 
| 
       20 
19 
     | 
    
         
             
                            cd #{context_path(context)} && \
         
     | 
| 
       21 
20 
     | 
    
         
             
                            terraform taint \
         
     | 
| 
       22 
     | 
    
         
            -
                            #{options[:module] ? "-module=#{options[:module]}" : ""} \
         
     | 
| 
       23 
21 
     | 
    
         
             
                            #{options[:resource]}
         
     | 
| 
       24 
22 
     | 
    
         
             
                          TAINT_COMMAND
         
     | 
| 
       25 
23 
     | 
    
         
             
                          syscall taint_command.squeeze(' ')
         
     | 
    
        data/lib/proteus/common.rb
    CHANGED
    
    | 
         @@ -3,10 +3,8 @@ require 'proteus/commands/clean' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'proteus/commands/destroy'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'proteus/commands/graph'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'proteus/commands/import'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'proteus/commands/move'
         
     | 
| 
       7 
6 
     | 
    
         
             
            require 'proteus/commands/output'
         
     | 
| 
       8 
7 
     | 
    
         
             
            require 'proteus/commands/plan'
         
     | 
| 
       9 
     | 
    
         
            -
            require 'proteus/commands/remove'
         
     | 
| 
       10 
8 
     | 
    
         
             
            require 'proteus/commands/render'
         
     | 
| 
       11 
9 
     | 
    
         
             
            require 'proteus/commands/taint'
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
         @@ -16,7 +14,9 @@ module Proteus 
     | 
|
| 
       16 
14 
     | 
    
         
             
                include Proteus::Helpers::PathHelpers
         
     | 
| 
       17 
15 
     | 
    
         | 
| 
       18 
16 
     | 
    
         
             
                Proteus::Commands.constants.each do |command|
         
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
      
 17 
     | 
    
         
            +
                  unless command == :State
         
     | 
| 
      
 18 
     | 
    
         
            +
                    include const_get("Proteus::Commands::#{command}")
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                private
         
     | 
| 
         @@ -56,10 +56,13 @@ module Proteus 
     | 
|
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                def aws_profile
         
     | 
| 
       59 
     | 
    
         
            -
                  config[:providers].select {|p| p[:name] == 'aws' }.first[:environments].each do | 
     | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
      
 59 
     | 
    
         
            +
                  config[:providers].select {|p| p[:name] == 'aws' }.first[:environments].each do |env|
         
     | 
| 
      
 60 
     | 
    
         
            +
                    env[:match].each do |m|
         
     | 
| 
      
 61 
     | 
    
         
            +
                      return "-var 'aws_profile=#{env[:profile]}'" if environment == m
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
       61 
63 
     | 
    
         
             
                  end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  raise "No AWS profile found in config."
         
     | 
| 
       63 
66 
     | 
    
         
             
                end
         
     | 
| 
       64 
67 
     | 
    
         | 
| 
       65 
68 
     | 
    
         
             
                def dryrun
         
     | 
    
        data/lib/proteus/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: dh-proteus
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Simon Albrecht
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-01-31 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -108,48 +108,6 @@ dependencies: 
     | 
|
| 
       108 
108 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       109 
109 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       110 
110 
     | 
    
         
             
                    version: 2.7.0
         
     | 
| 
       111 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       112 
     | 
    
         
            -
              name: aws-sdk-rds
         
     | 
| 
       113 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       114 
     | 
    
         
            -
                requirements:
         
     | 
| 
       115 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       116 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       117 
     | 
    
         
            -
                    version: 1.11.0
         
     | 
| 
       118 
     | 
    
         
            -
              type: :runtime
         
     | 
| 
       119 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       120 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       121 
     | 
    
         
            -
                requirements:
         
     | 
| 
       122 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       123 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       124 
     | 
    
         
            -
                    version: 1.11.0
         
     | 
| 
       125 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       126 
     | 
    
         
            -
              name: aws-sdk-route53
         
     | 
| 
       127 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       128 
     | 
    
         
            -
                requirements:
         
     | 
| 
       129 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       130 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       131 
     | 
    
         
            -
                    version: 1.7.0
         
     | 
| 
       132 
     | 
    
         
            -
              type: :runtime
         
     | 
| 
       133 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       134 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       135 
     | 
    
         
            -
                requirements:
         
     | 
| 
       136 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       137 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       138 
     | 
    
         
            -
                    version: 1.7.0
         
     | 
| 
       139 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       140 
     | 
    
         
            -
              name: aws-sdk-elasticsearchservice
         
     | 
| 
       141 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       142 
     | 
    
         
            -
                requirements:
         
     | 
| 
       143 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       144 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       145 
     | 
    
         
            -
                    version: 1.4.0
         
     | 
| 
       146 
     | 
    
         
            -
              type: :runtime
         
     | 
| 
       147 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       148 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       149 
     | 
    
         
            -
                requirements:
         
     | 
| 
       150 
     | 
    
         
            -
                - - "~>"
         
     | 
| 
       151 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       152 
     | 
    
         
            -
                    version: 1.4.0
         
     | 
| 
       153 
111 
     | 
    
         
             
            description: 
         
     | 
| 
       154 
112 
     | 
    
         
             
            email:
         
     | 
| 
       155 
113 
     | 
    
         
             
            - simon.albrecht@deliveryhero.com
         
     | 
| 
         @@ -179,11 +137,13 @@ files: 
     | 
|
| 
       179 
137 
     | 
    
         
             
            - lib/proteus/commands/destroy.rb
         
     | 
| 
       180 
138 
     | 
    
         
             
            - lib/proteus/commands/graph.rb
         
     | 
| 
       181 
139 
     | 
    
         
             
            - lib/proteus/commands/import.rb
         
     | 
| 
       182 
     | 
    
         
            -
            - lib/proteus/commands/move.rb
         
     | 
| 
       183 
140 
     | 
    
         
             
            - lib/proteus/commands/output.rb
         
     | 
| 
       184 
141 
     | 
    
         
             
            - lib/proteus/commands/plan.rb
         
     | 
| 
       185 
     | 
    
         
            -
            - lib/proteus/commands/remove.rb
         
     | 
| 
       186 
142 
     | 
    
         
             
            - lib/proteus/commands/render.rb
         
     | 
| 
      
 143 
     | 
    
         
            +
            - lib/proteus/commands/state/list.rb
         
     | 
| 
      
 144 
     | 
    
         
            +
            - lib/proteus/commands/state/move.rb
         
     | 
| 
      
 145 
     | 
    
         
            +
            - lib/proteus/commands/state/remove.rb
         
     | 
| 
      
 146 
     | 
    
         
            +
            - lib/proteus/commands/state/show.rb
         
     | 
| 
       187 
147 
     | 
    
         
             
            - lib/proteus/commands/taint.rb
         
     | 
| 
       188 
148 
     | 
    
         
             
            - lib/proteus/common.rb
         
     | 
| 
       189 
149 
     | 
    
         
             
            - lib/proteus/config/config.rb
         
     | 
| 
         @@ -1,28 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Proteus
         
     | 
| 
       2 
     | 
    
         
            -
              module Commands
         
     | 
| 
       3 
     | 
    
         
            -
                module Move
         
     | 
| 
       4 
     | 
    
         
            -
                  def self.included(thor_class)
         
     | 
| 
       5 
     | 
    
         
            -
                    thor_class.class_eval do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                      desc "move FROM TO", "Moves an existing resource within the Terraform state"
         
     | 
| 
       8 
     | 
    
         
            -
                      def move(from, to)
         
     | 
| 
       9 
     | 
    
         
            -
                        init(verbose: parent_options[:verbose])
         
     | 
| 
       10 
     | 
    
         
            -
                        confirm question: "Do you really want to move #{from} to #{to} in context '(#{context}, #{environment})'?", color: :on_red, exit_code: 0 do
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                          state_move_command = <<~STATE_MOVE_COMMAND
         
     | 
| 
       13 
     | 
    
         
            -
                            cd #{context_path(context)} && \
         
     | 
| 
       14 
     | 
    
         
            -
                            terraform state mv \
         
     | 
| 
       15 
     | 
    
         
            -
                            -var-file=#{var_file(context, environment)} \
         
     | 
| 
       16 
     | 
    
         
            -
                            #{aws_profile} \
         
     | 
| 
       17 
     | 
    
         
            -
                            #{from} \
         
     | 
| 
       18 
     | 
    
         
            -
                            #{to}
         
     | 
| 
       19 
     | 
    
         
            -
                          STATE_MOVE_COMMAND
         
     | 
| 
       20 
     | 
    
         
            -
                          syscall state_move_command.squeeze(' '), dryrun:  dryrun
         
     | 
| 
       21 
     | 
    
         
            -
                        end
         
     | 
| 
       22 
     | 
    
         
            -
                      end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                    end
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,69 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Proteus
         
     | 
| 
       2 
     | 
    
         
            -
              module Commands
         
     | 
| 
       3 
     | 
    
         
            -
                module Remove
         
     | 
| 
       4 
     | 
    
         
            -
                  def self.included(thor_class)
         
     | 
| 
       5 
     | 
    
         
            -
                    thor_class.class_eval do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                      desc "remove", "Remove a resource from the terraform state"
         
     | 
| 
       8 
     | 
    
         
            -
                      long_desc <<-LONGDESC
         
     | 
| 
       9 
     | 
    
         
            -
                        Remove a resource from the terraform state
         
     | 
| 
       10 
     | 
    
         
            -
                        --bulk Enables bulk import mode
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                        --resource_address Terraform address of resource to remove from the terraform state
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                        --resources_file File containing resource addresses and identifiers
         
     | 
| 
       15 
     | 
    
         
            -
                      LONGDESC
         
     | 
| 
       16 
     | 
    
         
            -
                      option :bulk, type: :boolean, aliases: "-b", required: false, default: false
         
     | 
| 
       17 
     | 
    
         
            -
                      option :resource_address, type: :string, aliases: "-a", required: false, default: nil
         
     | 
| 
       18 
     | 
    
         
            -
                      option :resources_file, type: :string, aliases: "-f", required: false, default: nil
         
     | 
| 
       19 
     | 
    
         
            -
                      def remove
         
     | 
| 
       20 
     | 
    
         
            -
                        if options[:bulk]
         
     | 
| 
       21 
     | 
    
         
            -
                          if !options[:resources_file]
         
     | 
| 
       22 
     | 
    
         
            -
                            say "Supply a file containing resource identifiers and Terraform addresses for bulk operations", :red
         
     | 
| 
       23 
     | 
    
         
            -
                            exit 1
         
     | 
| 
       24 
     | 
    
         
            -
                          end
         
     | 
| 
       25 
     | 
    
         
            -
                        else
         
     | 
| 
       26 
     | 
    
         
            -
                          if !options[:resource_address]
         
     | 
| 
       27 
     | 
    
         
            -
                            say "You need to supply a resource address.", :red
         
     | 
| 
       28 
     | 
    
         
            -
                            exit 1
         
     | 
| 
       29 
     | 
    
         
            -
                          end
         
     | 
| 
       30 
     | 
    
         
            -
                        end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                        init(verbose: parent_options[:verbose])
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                        confirm question: "Do you really want to run 'terraform state rm' in context '(#{context}, #{environment})'?", color: :on_red, exit_code: 0 do
         
     | 
| 
       35 
     | 
    
         
            -
                          state_remove_command = <<~STATE_REMOVE_COMMAND
         
     | 
| 
       36 
     | 
    
         
            -
                            cd #{context_path(context)} && \
         
     | 
| 
       37 
     | 
    
         
            -
                            terraform state rm \
         
     | 
| 
       38 
     | 
    
         
            -
                            %{resource_addresses}
         
     | 
| 
       39 
     | 
    
         
            -
                          STATE_REMOVE_COMMAND
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                          if options[:bulk]
         
     | 
| 
       42 
     | 
    
         
            -
                            if File.file?(options[:resources_file])
         
     | 
| 
       43 
     | 
    
         
            -
                              File.open(options[:resources_file], "r") do |file|
         
     | 
| 
       44 
     | 
    
         
            -
                                resource_addresses = []
         
     | 
| 
       45 
     | 
    
         
            -
                                file.each_line do |line|
         
     | 
| 
       46 
     | 
    
         
            -
                                  resource = line.chomp.split(" = ")
         
     | 
| 
       47 
     | 
    
         
            -
                                  resource_addresses << resource[0]
         
     | 
| 
       48 
     | 
    
         
            -
                                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                                resource_addresses.each_slice(500) do |slice|
         
     | 
| 
       51 
     | 
    
         
            -
                                  syscall (state_remove_command % { resource_addresses: slice.join(' ') }).squeeze(' ')
         
     | 
| 
       52 
     | 
    
         
            -
                                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                              end
         
     | 
| 
       55 
     | 
    
         
            -
                            else
         
     | 
| 
       56 
     | 
    
         
            -
                              say "File #{options[:resources_file]} does not exist.", :red
         
     | 
| 
       57 
     | 
    
         
            -
                              exit 1
         
     | 
| 
       58 
     | 
    
         
            -
                            end
         
     | 
| 
       59 
     | 
    
         
            -
                          else
         
     | 
| 
       60 
     | 
    
         
            -
                            syscall (state_remove_command % { resource_addresses: options[:resource_address] })
         
     | 
| 
       61 
     | 
    
         
            -
                          end
         
     | 
| 
       62 
     | 
    
         
            -
                        end
         
     | 
| 
       63 
     | 
    
         
            -
                      end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                    end
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
     | 
    
         
            -
                end
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
            end
         
     |