Sha256: 48946100ebcde37b18713c0b75f9bfef7a5ecccf2897f1b55e9489b28264edee

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 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)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

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

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

          resources
        end
      end

      private

      def iam_groups
        @client.list_groups.map(&:groups).flatten
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terraforming-0.12.0 lib/terraforming/resource/iam_group.rb
terraforming-0.11.0 lib/terraforming/resource/iam_group.rb
terraforming-0.10.0 lib/terraforming/resource/iam_group.rb