Class: Terraforming::Resource::DBSecurityGroup

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/db_security_group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ DBSecurityGroup

Returns a new instance of DBSecurityGroup.



14
15
16
# File 'lib/terraforming/resource/db_security_group.rb', line 14

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::RDS::Client.new) ⇒ Object



6
7
8
# File 'lib/terraforming/resource/db_security_group.rb', line 6

def self.tf(client: Aws::RDS::Client.new)
  self.new(client).tf
end

.tfstate(client: Aws::RDS::Client.new) ⇒ Object



10
11
12
# File 'lib/terraforming/resource/db_security_group.rb', line 10

def self.tfstate(client: Aws::RDS::Client.new)
  self.new(client).tfstate
end

Instance Method Details

#tfObject



18
19
20
# File 'lib/terraforming/resource/db_security_group.rb', line 18

def tf
  apply_template(@client, "tf/db_security_group")
end

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/terraforming/resource/db_security_group.rb', line 22

def tfstate
  db_security_groups.inject({}) do |resources, security_group|
    attributes = {
      "db_subnet_group_name" => security_group.db_security_group_name,
      "id" => security_group.db_security_group_name,
      "ingress.#" => ingresses_of(security_group).length.to_s,
      "name" => security_group.db_security_group_name,
    }
    resources["aws_db_security_group.#{module_name_of(security_group)}"] = {
      "type" => "aws_db_security_group",
      "primary" => {
        "id" => security_group.db_security_group_name,
        "attributes" => attributes
      }
    }

    resources
  end
end