Sha256: c12ab455324c0c78c89ff3a345f1ef1af96c3882b753edee58e3b93127a5f997

Contents?: true

Size: 1.3 KB

Versions: 12

Compression:

Stored size: 1.3 KB

Contents

module Terraforming
  module Resource
    class IAMPolicy
      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_policy")
      end

      def tfstate
        iam_policies.inject({}) do |resources, policy|
          version = iam_policy_version_of(policy)
          attributes = {
            "id" => policy.arn,
            "name" => policy.policy_name,
            "path" => policy.path,
            "policy" => prettify_policy(version.document, breakline: true, unescape: true),
          }
          resources["aws_iam_policy.#{policy.policy_name}"] = {
            "type" => "aws_iam_policy",
            "primary" => {
              "id" => policy.arn,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def iam_policies
        @client.list_policies(scope: "Local").policies
      end

      def iam_policy_version_of(policy)
        @client.get_policy_version(policy_arn: policy.arn, version_id: policy.default_version_id).policy_version
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
terraforming-0.7.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.6.2 lib/terraforming/resource/iam_policy.rb
terraforming-0.6.1 lib/terraforming/resource/iam_policy.rb
terraforming-0.6.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.5.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.4.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.3.2 lib/terraforming/resource/iam_policy.rb
terraforming-0.3.1 lib/terraforming/resource/iam_policy.rb
terraforming-0.3.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.2.0 lib/terraforming/resource/iam_policy.rb
terraforming-0.1.6 lib/terraforming/resource/iam_policy.rb
terraforming-0.1.5 lib/terraforming/resource/iam_policy.rb