Sha256: 068e75c19167cd9be165e84df85050ad16afa60e41ef170111e91ff2fe9f9777

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Terraforming
  module Resource
    class IAMGroup
      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_group")
      end

      def tfstate(tfstate_base)
        resources = iam_groups.inject({}) do |result, group|
          attributes = {
            "arn"=> group.arn,
            "id" => group.group_name,
            "name" => group.group_name,
            "path" => group.path,
            "unique_id" => group.group_id,
          }
          result["aws_iam_group.#{group.group_name}"] = {
            "type" => "aws_iam_group",
            "primary" => {
              "id" => group.group_name,
              "attributes" => attributes
            }
          }

          result
        end

        generate_tfstate(resources, tfstate_base)
      end

      private

      def iam_groups
        @client.list_groups.groups
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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