File tree Expand file tree Collapse file tree 6 files changed +96
-1
lines changed
lib/core/terraform_config
dummy/.controlplane/templates Expand file tree Collapse file tree 6 files changed +96
-1
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module TerraformConfig
4
+ class Agent < Base
5
+ attr_reader :name , :description , :tags
6
+
7
+ def initialize ( name :, description : nil , tags : nil )
8
+ super ( )
9
+
10
+ @name = name
11
+ @description = description
12
+ @tags = tags
13
+ end
14
+
15
+ def to_tf
16
+ block :resource , :cpln_agent , name do
17
+ argument :name , name
18
+ argument :description , description , optional : true
19
+ argument :tags , tags , optional : true
20
+ end
21
+ end
22
+ end
23
+ end
Original file line number Diff line number Diff line change 2
2
3
3
module TerraformConfig
4
4
class Generator # rubocop:disable Metrics/ClassLength
5
- SUPPORTED_TEMPLATE_KINDS = %w[ gvc secret identity policy volumeset workload auditctx ] . freeze
5
+ SUPPORTED_TEMPLATE_KINDS = %w[ gvc secret identity policy volumeset workload auditctx agent ] . freeze
6
6
WORKLOAD_SPEC_KEYS = %i[
7
7
type
8
8
containers
@@ -113,6 +113,10 @@ def auditctx_config_params
113
113
template . slice ( :name , :description , :tags )
114
114
end
115
115
116
+ def agent_config_params
117
+ template . slice ( :name , :description , :tags )
118
+ end
119
+
116
120
def workload_config_params
117
121
template
118
122
. slice ( :name , :description , :tags )
Original file line number Diff line number Diff line change 24
24
maintenance_envs
25
25
maintenance-with-external-image
26
26
audit_contexts
27
+ agents
27
28
] . freeze
28
29
29
30
describe Command ::Terraform ::Generate do
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe TerraformConfig ::Agent do
6
+ let ( :config ) { described_class . new ( **options ) }
7
+
8
+ describe "#to_tf" do
9
+ subject ( :generated ) { config . to_tf }
10
+
11
+ let ( :options ) do
12
+ {
13
+ name : "agent-name" ,
14
+ description : "agent description" ,
15
+ tags : { "tag1" => "true" , "tag2" => "value" }
16
+ }
17
+ end
18
+
19
+ it "generates correct config" do
20
+ expect ( generated ) . to eq (
21
+ <<~EXPECTED
22
+ resource "cpln_agent" "agent-name" {
23
+ name = "agent-name"
24
+ description = "agent description"
25
+ tags = {
26
+ tag1 = "true"
27
+ tag2 = "value"
28
+ }
29
+ }
30
+ EXPECTED
31
+ )
32
+ end
33
+ end
34
+ end
Original file line number Diff line number Diff line change 559
559
expect ( main_tf_config . job ) . to be_nil
560
560
end
561
561
end
562
+
563
+ context "when template's kind is agent" do
564
+ let ( :template ) do
565
+ {
566
+ "kind" => "agent" ,
567
+ "name" => "agent-name" ,
568
+ "description" => "agent description" ,
569
+ "tags" => { "tag1" => "tag1_value" , "tag2" => "tag2_value" }
570
+ }
571
+ end
572
+
573
+ it "generates correct terraform config and filename for it" , :aggregate_failures do
574
+ expected_filename = "agents.tf"
575
+
576
+ tf_configs = generator . tf_configs
577
+ expect ( tf_configs . count ) . to eq ( 1 )
578
+
579
+ filenames = tf_configs . keys
580
+ expect ( filenames ) . to contain_exactly ( expected_filename )
581
+
582
+ tf_config = tf_configs [ expected_filename ]
583
+ expect ( tf_config ) . to be_an_instance_of ( TerraformConfig ::Agent )
584
+
585
+ expect ( tf_config . name ) . to eq ( "agent-name" )
586
+ expect ( tf_config . description ) . to eq ( "agent description" )
587
+ expect ( tf_config . tags ) . to eq ( tag1 : "tag1_value" , tag2 : "tag2_value" )
588
+ end
589
+ end
562
590
end
Original file line number Diff line number Diff line change
1
+ kind : agent
2
+ name : agent-name
3
+ description : agent description
4
+ tags :
5
+ tag1 : value1
You can’t perform that action at this time.
0 commit comments