Class: TerraformConfig::Policy

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

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

TARGET_KINDS =
%w[
  agent auditctx cloudaccount domain group gvc identity image ipset kubernetes location
  org policy quota secret serviceaccount task user volumeset workload
].freeze
GVC_REQUIRED_TARGET_KINDS =
%w[identity workload volumeset].freeze

Constants included from Dsl

Dsl::EXPRESSION_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#locals

Methods included from Dsl

#argument, #block

Constructor Details

#initialize(name:, description: nil, tags: nil, target_kind: nil, gvc: nil, target: nil, target_links: nil, target_query: nil, bindings: nil) ⇒ Policy

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/core/terraform_config/policy.rb', line 14

def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
  name:,
  description: nil,
  tags: nil,
  target_kind: nil,
  gvc: nil,
  target: nil,
  target_links: nil,
  target_query: nil,
  bindings: nil
)
  super()

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

  @target_kind = target_kind
  validate_target_kind!

  @gvc = gvc
  validate_gvc!

  @target = target
  @target_links = target_links

  @target_query = target_query&.deep_underscore_keys&.deep_symbolize_keys
  @bindings = bindings&.map { |data| data.deep_underscore_keys.deep_symbolize_keys }
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def bindings
  @bindings
end

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def description
  @description
end

#gvcObject (readonly)

Returns the value of attribute gvc.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def gvc
  @gvc
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def tags
  @tags
end

#targetObject (readonly)

Returns the value of attribute target.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def target
  @target
end

#target_kindObject (readonly)

Returns the value of attribute target_kind.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def target_kind
  @target_kind
end

Returns the value of attribute target_links.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def target_links
  @target_links
end

#target_queryObject (readonly)

Returns the value of attribute target_query.



12
13
14
# File 'lib/core/terraform_config/policy.rb', line 12

def target_query
  @target_query
end

Instance Method Details

#importable?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/core/terraform_config/policy.rb', line 44

def importable?
  true
end

#referenceObject



48
49
50
# File 'lib/core/terraform_config/policy.rb', line 48

def reference
  "cpln_policy.#{name}"
end

#to_tfObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/core/terraform_config/policy.rb', line 52

def to_tf
  block :resource, :cpln_policy, name do
    argument :name, name

    %i[description tags target_kind gvc target target_links].each do |arg_name|
      argument arg_name, send(arg_name), optional: true
    end

    bindings_tf
    target_query_tf
  end
end