Sha256: a467ad171fa9877f7f88238d23c9dbdc5de9cf91bdc8199f47ed0cfd19fe5c4e

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

module Terraforming
  module Resource
    class KMSAlias
      include Terraforming::Util

      def self.tf(client: Aws::KMS::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::KMS::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/kms_alias")
      end

      def tfstate
        aliases.inject({}) do |resources, als|
          resources["aws_kms_alias.#{module_name_of(als)}"] = {
            "type" => "aws_kms_alias",
            "primary" => {
              "id" => als.alias_name,
              "attributes" => {
                "arn" => als.alias_arn,
                "id" => als.alias_name,
                "name" => als.alias_name,
                "target_key_id" => als.target_key_id,
              },
            },
          }
          resources
        end
      end

      private

      def aliases
        @client.list_aliases.aliases.reject { |als| managed_master_key_alias?(als) }
      end

      def managed_master_key_alias?(als)
        als.alias_name =~ %r{\Aalias/aws/}
      end

      def module_name_of(als)
        normalize_module_name(als.alias_name.gsub(%r{\Aalias/}, ""))
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
terraforming-0.18.0 lib/terraforming/resource/kms_alias.rb
terraforming-0.17.0 lib/terraforming/resource/kms_alias.rb
terraforming-0.16.0 lib/terraforming/resource/kms_alias.rb
terraforming-0.15.0 lib/terraforming/resource/kms_alias.rb
aws-insight-0.14.1 lib/terraforming/resource/kms_alias.rb
aws-insight-0.14.0 lib/terraforming/resource/kms_alias.rb
terraforming-0.14.0 lib/terraforming/resource/kms_alias.rb
terraforming-0.13.2 lib/terraforming/resource/kms_alias.rb
terraforming-0.13.1 lib/terraforming/resource/kms_alias.rb
terraforming-0.13.0 lib/terraforming/resource/kms_alias.rb