Class: Pangea::Resources::Builders::OutputBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/resources/builders/output_builder.rb

Constant Summary collapse

COMMON_OUTPUTS =
{
  aws: [:id, :arn],
  cloudflare: [:id],
  hcloud: [:id]
}.freeze
OUTPUT_PRESETS =
{
  aws_vpc: [:id, :arn, :cidr_block, :default_network_acl_id,
            :default_route_table_id, :default_security_group_id,
            :enable_dns_hostnames, :enable_dns_support, :main_route_table_id],
  aws_subnet: [:id, :arn, :cidr_block, :availability_zone, :vpc_id],
  aws_security_group: [:id, :arn, :name, :vpc_id, :owner_id],
  aws_instance: [:id, :arn, :public_ip, :private_ip, :public_dns, :private_dns],
  aws_s3_bucket: [:id, :arn, :bucket_domain_name, :bucket_regional_domain_name, :region],
  aws_iam_role: [:id, :arn, :name, :unique_id],
  aws_lambda_function: [:id, :arn, :invoke_arn, :qualified_arn, :version],

  cloudflare_zone: [:id, :status, :name_servers, :vanity_name_servers, :verification_key, :meta],
  cloudflare_record: [:id, :hostname, :proxied, :created_on, :modified_on],
  cloudflare_worker_script: [:id],
  cloudflare_pages_project: [:id, :subdomain, :domains],

  hcloud_server: [:id, :name, :ipv4_address, :ipv6_address, :status],
  hcloud_network: [:id, :name, :ip_range]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_type, resource_name, *custom_outputs) ⇒ OutputBuilder

Returns a new instance of OutputBuilder.



49
50
51
52
53
54
# File 'lib/pangea/resources/builders/output_builder.rb', line 49

def initialize(resource_type, resource_name, *custom_outputs)
  @resource_type = resource_type.to_sym
  @resource_name = resource_name
  @custom_outputs = custom_outputs.flatten
  @preset = nil
end

Instance Attribute Details

#custom_outputsObject (readonly)

Returns the value of attribute custom_outputs.



47
48
49
# File 'lib/pangea/resources/builders/output_builder.rb', line 47

def custom_outputs
  @custom_outputs
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



47
48
49
# File 'lib/pangea/resources/builders/output_builder.rb', line 47

def resource_name
  @resource_name
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



47
48
49
# File 'lib/pangea/resources/builders/output_builder.rb', line 47

def resource_type
  @resource_type
end

Instance Method Details

#arnObject



80
81
82
# File 'lib/pangea/resources/builders/output_builder.rb', line 80

def arn
  interpolation_string(:arn)
end

#buildObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/pangea/resources/builders/output_builder.rb', line 61

def build
  outputs = {}
  output_keys = determine_outputs

  output_keys.each do |output_key|
    outputs[output_key] = interpolation_string(output_key)
  end

  outputs
end

#idObject



76
77
78
# File 'lib/pangea/resources/builders/output_builder.rb', line 76

def id
  interpolation_string(:id)
end

#interpolation_string(attribute) ⇒ Object



72
73
74
# File 'lib/pangea/resources/builders/output_builder.rb', line 72

def interpolation_string(attribute)
  "${#{resource_type}.#{resource_name}.#{attribute}}"
end

#with_preset(preset_name = nil) ⇒ Object



56
57
58
59
# File 'lib/pangea/resources/builders/output_builder.rb', line 56

def with_preset(preset_name = nil)
  @preset = preset_name || @resource_type
  self
end