Class: Terrafying::Components::InstanceProfile

Inherits:
Terrafying::Context
  • Object
show all
Defined in:
lib/terrafying/components/instanceprofile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstanceProfile

Returns a new instance of InstanceProfile.



16
17
18
# File 'lib/terrafying/components/instanceprofile.rb', line 16

def initialize
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/terrafying/components/instanceprofile.rb', line 6

def id
  @id
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



6
7
8
# File 'lib/terrafying/components/instanceprofile.rb', line 6

def resource_name
  @resource_name
end

#role_arnObject (readonly)

Returns the value of attribute role_arn.



6
7
8
# File 'lib/terrafying/components/instanceprofile.rb', line 6

def role_arn
  @role_arn
end

#role_resourceObject (readonly)

Returns the value of attribute role_resource.



6
7
8
# File 'lib/terrafying/components/instanceprofile.rb', line 6

def role_resource
  @role_resource
end

Class Method Details

.create(name, options = {}) ⇒ Object



8
9
10
# File 'lib/terrafying/components/instanceprofile.rb', line 8

def self.create(name, options = {})
  InstanceProfile.new.create name, options
end

.find(name) ⇒ Object



12
13
14
# File 'lib/terrafying/components/instanceprofile.rb', line 12

def self.find(name)
  InstanceProfile.new.find name
end

Instance Method Details

#add_statement!(statement) ⇒ Object



85
86
87
88
# File 'lib/terrafying/components/instanceprofile.rb', line 85

def add_statement!(statement)
  @statements << statement
  @policy_config[:policy] = policy
end

#create(name, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/terrafying/components/instanceprofile.rb', line 24

def create(name, options = {})
  options = {
    statements: []
  }.merge(options)

  resource :aws_iam_role, name,
           name: name,
           assume_role_policy: JSON.pretty_generate(
             Version: '2012-10-17',
             Statement: [
               {
                 Effect: 'Allow',
                 Principal: { "Service": 'ec2.amazonaws.com' },
                 Action: 'sts:AssumeRole'
               }
             ]
           )

  @id = resource :aws_iam_instance_profile, name,
                 name: name,
                 role: output_of(:aws_iam_role, name, :name)
  @name = name
  @resource_name = "aws_iam_instance_profile.#{name}"

  @role_arn = output_of(:aws_iam_role, name, :arn)
  @role_resource = "aws_iam_role.#{name}"

  @statements = [
    {
      Sid: 'Stmt1442396947000',
      Effect: 'Allow',
      Action: [
        'iam:GetGroup',
        'iam:GetSSHPublicKey',
        'iam:GetUser',
        'iam:ListSSHPublicKeys'
      ],
      Resource: [
        'arn:aws:iam::*'
      ]
    }
  ].push(*options[:statements])

  @policy_config = {
    name: @name,
    policy: policy,
    role: output_of(:aws_iam_role, @name, :name)
  }

  resource :aws_iam_role_policy, @name, @policy_config

  self
end

#find(_name) ⇒ Object



20
21
22
# File 'lib/terrafying/components/instanceprofile.rb', line 20

def find(_name)
  raise 'unimplemented'
end

#policyObject



78
79
80
81
82
83
# File 'lib/terrafying/components/instanceprofile.rb', line 78

def policy
  JSON.pretty_generate(
    Version: '2012-10-17',
    Statement: @statements
  )
end