class PracticeTerraforming::Resource::IAMGroupPolicyAttachment

Public Class Methods

new(client) click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 20
def initialize(client)
  @client = client
end
tf(client: Aws::IAM::Client.new) click to toggle source

TODO: Select appropriate Client class from here: docs.aws.amazon.com/sdkforruby/api/index.html

# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 10
def self.tf(client: Aws::IAM::Client.new)
  self.new(client).tf
end
tfstate(client: Aws::IAM::Client.new) click to toggle source

TODO: Select appropriate Client class from here: docs.aws.amazon.com/sdkforruby/api/index.html

# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 16
def self.tfstate(client: Aws::IAM::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 24
def tf
  apply_template(@client, "tf/iam_group_policy_attachment")
end
tfstate() click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 28
def tfstate
  iam_group_policy_attachments.inject({}) do |resources, group_policy_attachment|
    attributes = {
      "id" => group_policy_attachment[:name],
      "policy_arn" => group_policy_attachment[:policy_arn],
      "group" => group_policy_attachment[:group]
    }
    resources["aws_iam_group_policy_attachment.#{module_name_of(group_policy_attachment)}"] = {
      "type" => "aws_iam_group_policy_attachment",
      "primary" => {
        "id" => group_policy_attachment[:name],
        "attributes" => attributes
      }
    }

    resources
  end
end

Private Instance Methods

attachment_name_from(group, policy) click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 49
def attachment_name_from(group, policy)
  "#{group.group_name}-#{policy.policy_name}-attachment"
end
iam_group_policy_attachments() click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 61
def iam_group_policy_attachments
  iam_groups.map do |group|
    policies_attached_to(group).map do |policy|
      {
        group: group.group_name,
        policy_arn: policy.policy_arn,
        name: attachment_name_from(group, policy)
      }
    end
  end.flatten
end
iam_groups() click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 53
def iam_groups
  @client.list_groups.map(&:groups).flatten
end
module_name_of(group_policy_attachment) click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 73
def module_name_of(group_policy_attachment)
  normalize_module_name(group_policy_attachment[:name])
end
policies_attached_to(group) click to toggle source
# File lib/practice_terraforming/resource/iam_group_policy_attachment.rb, line 57
def policies_attached_to(group)
  @client.list_attached_group_policies(group_name: group.group_name).attached_policies
end