Module: Tfrb::Resource::AwsIamPolicy

Extended by:
Tfrb::Resource
Defined in:
lib/tfrb/resource/aws_iam_policy.rb

Class Method Summary collapse

Methods included from Tfrb::Resource

aws_options, extended, get_custom_resource, get_state, import!, load_helpers!, preload, resolve_tfvar, set_default

Class Method Details

.load(base, environment_name, resource_type, new_resources) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tfrb/resource/aws_iam_policy.rb', line 124

def self.load(base, environment_name, resource_type, new_resources)
  new_resources.each do |resource_name, resource|
    client = ::Aws::IAM::Client.new(aws_options(base, resource))
    begin
      response = client.list_policies({
        scope: 'Local',
        path_prefix: '/',
        max_items: 1000
      })
      if policy = response.policies.find { |p| p.arn =~ /policy\/#{resource_name}$/ }
        id = policy.arn
        import!(base, resource_type, resource_name, id)
      end
    rescue ::Aws::IAM::Errors::NoSuchEntity
      # Does not exist to import
    end
  end
end