Class: Terraforming::Resource::RDS

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/rds.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) ⇒ RDS

Returns a new instance of RDS.



14
15
16
# File 'lib/terraforming/resource/rds.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/rds.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/rds.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/rds.rb', line 18

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

#tfstateObject



22
23
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
# File 'lib/terraforming/resource/rds.rb', line 22

def tfstate
  db_instances.inject({}) do |resources, instance|
    attributes = {
      "address" => instance.endpoint.address,
      "allocated_storage" => instance.allocated_storage.to_s,
      "availability_zone" => instance.availability_zone,
      "backup_retention_period" => instance.backup_retention_period.to_s,
      "backup_window" => instance.preferred_backup_window,
      "db_subnet_group_name" => instance.db_subnet_group ? instance.db_subnet_group.db_subnet_group_name : "",
      "endpoint" => instance.endpoint.address,
      "engine" => instance.engine,
      "engine_version" => instance.engine_version,
      "final_snapshot_identifier" => "#{instance.db_instance_identifier}-final",
      "id" => instance.db_instance_identifier,
      "identifier" => instance.db_instance_identifier,
      "instance_class" => instance.db_instance_class,
      "maintenance_window" => instance.preferred_maintenance_window,
      "multi_az" => instance.multi_az.to_s,
      "name" => instance.db_name,
      "parameter_group_name" => instance.db_parameter_groups[0].db_parameter_group_name,
      "password" => "xxxxxxxx",
      "port" => instance.endpoint.port.to_s,
      "publicly_accessible" => instance.publicly_accessible.to_s,
      "security_group_names.#" => instance.db_security_groups.length.to_s,
      "status" => instance.db_instance_status,
      "storage_type" => instance.storage_type,
      "username" => instance.master_username,
      "vpc_security_group_ids.#" => instance.vpc_security_groups.length.to_s,
    }
    resources["aws_db_instance.#{module_name_of(instance)}"] = {
      "type" => "aws_db_instance",
      "primary" => {
        "id" => instance.db_instance_identifier,
        "attributes" => attributes
      }
    }

    resources
  end
end