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.



18
19
20
# File 'lib/terrafying/components/instanceprofile.rb', line 18

def initialize()
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



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

def resource_name
  @resource_name
end

#role_arnObject (readonly)

Returns the value of attribute role_arn.



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

def role_arn
  @role_arn
end

#role_resourceObject (readonly)

Returns the value of attribute role_resource.



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

def role_resource
  @role_resource
end

Class Method Details

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



10
11
12
# File 'lib/terrafying/components/instanceprofile.rb', line 10

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

.find(name) ⇒ Object



14
15
16
# File 'lib/terrafying/components/instanceprofile.rb', line 14

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

Instance Method Details

#add_statement!(statement) ⇒ Object



93
94
95
96
# File 'lib/terrafying/components/instanceprofile.rb', line 93

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

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



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
77
78
79
80
81
82
# File 'lib/terrafying/components/instanceprofile.rb', line 26

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



22
23
24
# File 'lib/terrafying/components/instanceprofile.rb', line 22

def find(name)
  raise 'unimplemented'
end

#policyObject



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

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