Class: TerraformConfig::Workload

Inherits:
Base
  • Object
show all
Defined in:
lib/core/terraform_config/workload.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

RAW_ARGS =
%i[
  containers options local_options rollout_options security_options
  firewall_spec load_balancer job
].freeze
OPTIONS_KEYS =
%i[autoscaling capacity_ai suspend timeout_seconds].freeze
LOCAL_OPTIONS_KEYS =
(OPTIONS_KEYS + %i[location]).freeze
ROLLOUT_OPTIONS_KEYS =
%i[min_ready_seconds max_unavailable_replicas max_surge_replicas scaling_policy].freeze
SECURITY_OPTIONS_KEYS =
%i[file_system_group_id].freeze
LOAD_BALANCER_KEYS =
%i[direct geo_location].freeze
FIREWALL_SPEC_KEYS =
%i[internal external].freeze
VOLUME_KEYS =
%i[uri path].freeze
JOB_KEYS =
%i[schedule concurrency_policy history_limit restart_policy active_deadline_seconds].freeze
LIVENESS_PROBE_KEYS =
%i[
  exec http_get tcp_socket grpc
  failure_threshold initial_delay_seconds period_seconds success_threshold timeout_seconds
].freeze

Constants included from Dsl

Dsl::EXPRESSION_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dsl

#argument, #block

Constructor Details

#initialize(type:, gvc:, name:, containers:, description: nil, tags: nil, support_dynamic_tags: false, firewall_spec: nil, identity_link: nil, options: nil, local_options: nil, rollout_options: nil, security_options: nil, load_balancer: nil, job: nil) ⇒ Workload

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength



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
62
63
64
65
# File 'lib/core/terraform_config/workload.rb', line 27

def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
  type:,
  gvc:,
  name:,
  containers:,
  description: nil,
  tags: nil,
  support_dynamic_tags: false,
  firewall_spec: nil,
  identity_link: nil,
  options: nil,
  local_options: nil,
  rollout_options: nil,
  security_options: nil,
  load_balancer: nil,
  job: nil
)
  super()

  @type = type
  @gvc = gvc

  @name = name
  @description = description
  @tags = tags

  @containers = containers
  @firewall_spec = firewall_spec
  @identity_link = identity_link

  @options = options
  @local_options = local_options
  @rollout_options = rollout_options
  @security_options = security_options

  @load_balancer = load_balancer
  @support_dynamic_tags = support_dynamic_tags
  @job = job
end

Instance Attribute Details

#containersObject (readonly)

Returns the value of attribute containers.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def containers
  @containers
end

#descriptionObject (readonly)

Returns the value of attribute description.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def description
  @description
end

#firewall_specObject (readonly)

Returns the value of attribute firewall_spec.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def firewall_spec
  @firewall_spec
end

#gvcObject (readonly)

Returns the value of attribute gvc.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def gvc
  @gvc
end

Returns the value of attribute identity_link.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def identity_link
  @identity_link
end

#jobObject (readonly)

Returns the value of attribute job.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def job
  @job
end

#load_balancerObject (readonly)

Returns the value of attribute load_balancer.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def load_balancer
  @load_balancer
end

#local_optionsObject (readonly)

Returns the value of attribute local_options.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def local_options
  @local_options
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def options
  @options
end

#rollout_optionsObject (readonly)

Returns the value of attribute rollout_options.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def rollout_options
  @rollout_options
end

#security_optionsObject (readonly)

Returns the value of attribute security_options.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def security_options
  @security_options
end

#support_dynamic_tagsObject (readonly)

Returns the value of attribute support_dynamic_tags.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def support_dynamic_tags
  @support_dynamic_tags
end

#tagsObject (readonly)

Returns the value of attribute tags.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def tags
  @tags
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/core/terraform_config/workload.rb', line 23

def type
  @type
end

Instance Method Details

#importable?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/core/terraform_config/workload.rb', line 67

def importable?
  true
end

#localsObject



89
90
91
92
93
94
95
96
97
# File 'lib/core/terraform_config/workload.rb', line 89

def locals
  containers.reduce({}) do |result, container|
    envs = container[:env].to_h { |env_var| [env_var[:name], env_var[:value]] }
    next result if envs.empty?

    envs_name = :"#{container.fetch(:name)}_envs"
    result.merge("#{envs_name}.tf" => LocalVariable.new(envs_name => envs))
  end
end

#referenceObject



71
72
73
# File 'lib/core/terraform_config/workload.rb', line 71

def reference
  "module.#{name}.cpln_workload.workload"
end

#to_tfObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/core/terraform_config/workload.rb', line 75

def to_tf
  block :module, name do
    argument :source, "../workload"

    argument :type, type
    argument :name, name
    argument :gvc, gvc
    argument :identity_link, identity_link, optional: true
    argument :support_dynamic_tags, support_dynamic_tags, optional: true

    RAW_ARGS.each { |arg_name| argument arg_name, send(:"#{arg_name}_arg"), raw: true, optional: true }
  end
end