Class: Terraforming::Resource::Redshift

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

Returns a new instance of Redshift.



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

def initialize(client)
  @client = client
end

Class Method Details

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



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

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

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



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

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

Instance Method Details

#tfObject



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

def tf
  apply_template(@client, "tf/redshift")
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
# File 'lib/terraforming/resource/redshift.rb', line 22

def tfstate
  clusters.inject({}) do |resources, cluster|
    attributes = {
      "cluster_identifier"                  => cluster.cluster_identifier,
      "cluster_type"                        => cluster.number_of_nodes == 1 ? "single-node" : "multi-node",
      "node_type"                           => cluster.node_type,
      "master_password"                     => "xxxxxxxx",
      "master_username"                     => cluster.master_username,
      "availability_zone"                   => cluster.availability_zone,
      "preferred_maintenance_window"        => cluster.preferred_maintenance_window,
      "cluster_parameter_group_name"        => cluster.cluster_parameter_groups[0].parameter_group_name,
      "automated_snapshot_retention_period" => cluster.automated_snapshot_retention_period.to_s,
      "port"                                => cluster.endpoint.port.to_s,
      "cluster_version"                     => cluster.cluster_version,
      "allow_version_upgrade"               => cluster.allow_version_upgrade.to_s,
      "number_of_nodes"                     => cluster.number_of_nodes.to_s,
      "publicly_accessible"                 => cluster.publicly_accessible.to_s,
      "encrypted"                           => cluster.encrypted.to_s,
      "skip_final_snapshot"                 => "true",
    }
    attributes["database_name"] = cluster.db_name if cluster.db_name

    resources["aws_redshift_cluster.#{module_name_of(cluster)}"] = {
      "type" => "aws_redshift_cluster",
      "primary" => {
        "id" => cluster.cluster_identifier,
        "attributes" => attributes
      }
    }

    resources
  end
end