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

#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

#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
# 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"
                   }
                 ]
               }
             )
           }

  resource :aws_iam_role_policy, name, {
             name: name,
             policy: JSON.pretty_generate(
               {
                 Version: "2012-10-17",
                 Statement: [
                   {
                     Sid: "Stmt1442396947000",
                     Effect: "Allow",
                     Action: [
                       "iam:GetGroup",
                       "iam:GetSSHPublicKey",
                       "iam:GetUser",
                       "iam:ListSSHPublicKeys"
                     ],
                     Resource: [
                       "arn:aws:iam::*"
                     ]
                   }
                 ].push(*options[:statements])
               }
             ),
             role: output_of(:aws_iam_role, name, :name)
           }

  @id = resource :aws_iam_instance_profile, name, {
                   name: name,
                   role: output_of(:aws_iam_role, name, :name),
                 }

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

  self
end

#find(name) ⇒ Object



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

def find(name)
  raise 'unimplemented'
end