class Terraforming::Resource::RDS

Public Class Methods

new(client) click to toggle source
# File lib/terraforming/resource/rds.rb, line 14
def initialize(client)
  @client = client
end
tf(client: Aws::RDS::Client.new) click to toggle source
# 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) click to toggle source
# File lib/terraforming/resource/rds.rb, line 10
def self.tfstate(client: Aws::RDS::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/terraforming/resource/rds.rb, line 18
def tf
  apply_template(@client, "tf/rds")
end
tfstate() click to toggle source
# 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

Private Instance Methods

db_instances() click to toggle source
# File lib/terraforming/resource/rds.rb, line 65
def db_instances
  @client.describe_db_instances.map(&:db_instances).flatten
end
module_name_of(instance) click to toggle source
# File lib/terraforming/resource/rds.rb, line 69
def module_name_of(instance)
  normalize_module_name(instance.db_instance_identifier)
end