Sha256: fb7513bc9ed2731ebee3ab9185f83b4f1454d07aa140e98cf357de72388ddf52

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 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, tfstate_base: nil)
        self.new(client).tfstate(tfstate_base)
      end

      def initialize(client)
        @client = client
      end

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

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

          result
        end

        generate_tfstate(resources, tfstate_base)
      end

      private

      def iam_instance_profiles
        @client.list_instance_profiles.instance_profiles
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
terraforming-0.1.3 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.1.2 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.1.1 lib/terraforming/resource/iam_instance_profile.rb
terraforming-0.1.0 lib/terraforming/resource/iam_instance_profile.rb