Class: GeoEngineer::Resources::AwsIamPolicyAttachment

Inherits:
GeoEngineer::Resource show all
Defined in:
lib/geoengineer/resources/aws_iam_policy_attachment.rb

Overview

AwsIamPolicyAttachment aws_iam_policy_attachment terrform resource,

Terraform Docs

Constant Summary

Constants inherited from GeoEngineer::Resource

GeoEngineer::Resource::DEFAULT_PROVIDER

Constants included from HasValidations

HasValidations::MAX_POLICY_LENGTH

Instance Attribute Summary

Attributes inherited from GeoEngineer::Resource

#environment, #id, #project, #template, #type

Instance Method Summary collapse

Methods inherited from GeoEngineer::Resource

_deep_symbolize_keys, _fetch_remote_resources, #_find_remote_resource, _ignore_remote_resource?, #_json_file, #_normalize_json, _resources_to_ignore, build, #build_individual_remote_resource, clear_remote_resource_cache, #depends_on, #duplicate, #duplicate_resource, #fetch_provider, fetch_remote_resources, #for_resource, #in_project, #initialize, #matched_remote_resource, #merge_parent_tags, #merge_tags, #new?, #remote_resource, #reset, #setup_tags_if_needed, #short_id, #short_name, #short_type, #terraform_name, #to_id_or_ref, #to_ref, #to_s, #to_terraform, #to_terraform_json, type_from_class_name, #validate_has_tag, #validate_required_subresource, #validate_subresource_required_attributes

Methods included from HasLifecycle

#execute_lifecycle, included

Methods included from HasValidations

#errors, included, #validate_at_least_one_present, #validate_cidr_block, #validate_only_one_present, #validate_policy_length, #validate_required_attributes

Methods included from HasSubResources

#assign_block, #attribute_missing, #delete_all_subresources, #delete_subresources_where, #subresources

Methods included from HasAttributes

#[], #[]=, #assign_attribute, #assign_block, #attribute_missing, #attribute_procs, #attributes, #delete, #eager_load_attributes, #method_missing, #reset_attributes, #retrieve_attribute, #terraform_attribute_ref, #terraform_attributes, #timeout

Constructor Details

This class inherits a constructor from GeoEngineer::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HasAttributes

Instance Method Details

#build_remote_resource_params(arn, entities) ⇒ Object


84
85
86
87
88
89
90
91
92
93
94
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 84

def build_remote_resource_params(arn, entities)
  {
    name: _policy.name,
    _terraform_id: arn,
    _geo_id: _policy.name,
    policy_arn: arn,
    users: entities[:policy_users].map(&:user_name),
    groups: entities[:policy_groups].map(&:group_name),
    roles: entities[:policy_roles].map(&:role_name)
  }
end

#find_remote_as_individual?Boolean


71
72
73
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 71

def find_remote_as_individual?
  true
end

#remote_resource_paramsObject


75
76
77
78
79
80
81
82
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 75

def remote_resource_params
  return {} unless _policy
  return {} unless _policy.remote_resource

  arn = _policy.remote_resource._terraform_id
  entities = AwsClients.iam(provider).list_entities_for_policy({ policy_arn: arn })
  build_remote_resource_params(arn, entities)
end

#shares_name_with_policy?Boolean


21
22
23
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 21

def shares_name_with_policy?
  policy && name.to_s == policy.name
end

#support_tags?Boolean


67
68
69
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 67

def support_tags?
  false
end

#terraform_groups_attributesObject


49
50
51
52
53
54
55
56
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 49

def terraform_groups_attributes
  return {} if groups.nil?

  groups_attributes = { 'groups.#' => groups.count.to_s }
  groups.each_with_index { |g, i| groups_attributes["groups.#{i}"] = g }

  groups_attributes
end

#terraform_roles_attributesObject


58
59
60
61
62
63
64
65
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 58

def terraform_roles_attributes
  return {} if roles.nil?

  roles_attributes = { 'roles.#' => roles.count.to_s }
  roles.each_with_index { |r, i| roles_attributes["roles.#{i}"] = r }

  roles_attributes
end

#terraform_users_attributesObject


40
41
42
43
44
45
46
47
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 40

def terraform_users_attributes
  return {} if users.nil?

  user_attributes = { 'users.#' => users.count.to_s }
  users.each_with_index { |u, i| user_attributes["users.#{i}"] = u }

  user_attributes
end

#to_terraform_stateObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 25

def to_terraform_state
  tfstate = super

  attributes = { 'name' => name.to_s }
  attributes['policy_arn'] = remote_resource.policy_arn if remote_resource

  attributes = attributes
               .merge(terraform_users_attributes)
               .merge(terraform_groups_attributes)
               .merge(terraform_roles_attributes)

  tfstate[:primary][:attributes] = attributes
  tfstate
end

#validate_shares_name_with_policyObject


16
17
18
19
# File 'lib/geoengineer/resources/aws_iam_policy_attachment.rb', line 16

def validate_shares_name_with_policy
  return "Policy attachment must share a name with the policy" unless shares_name_with_policy?
  []
end