Sha256: 66bad165a663340fc3731fff8060cfdb00e24e3d8808c0685aa2e41715019f1d

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

module Terraforming
  module Resource
    class IAMInstanceProfile
      include Terraforming::Util

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

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

      def initialize(client)
        @client = client
      end

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

      def tfstate
        iam_instance_profiles.inject({}) do |resources, profile|
          attributes = {
            "arn" => profile.arn,
            "id" => profile.instance_profile_name,
            "name" => profile.instance_profile_name,
            "path" => profile.path,
            "roles.#" => profile.roles.length.to_s,
          }
          resources["aws_iam_instance_profile.#{module_name_of(profile)}"] = {
            "type" => "aws_iam_instance_profile",
            "primary" => {
              "id" => profile.instance_profile_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def iam_instance_profiles
        @client.list_instance_profiles.map(&:instance_profiles).flatten
      end

      def module_name_of(profile)
        normalize_module_name(profile.instance_profile_name)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
terraforming-0.15.0 lib/terraforming/resource/iam_instance_profile.rb
aws-insight-0.14.1 lib/terraforming/resource/iam_instance_profile.rb
aws-insight-0.14.0 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.14.0 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.13.2 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.13.1 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.13.0 lib/terraforming/resource/iam_instance_profile.rb