@@ -33,7 +33,10 @@ func resourceTFERegistryModule() *schema.Resource {
33
33
},
34
34
35
35
CustomizeDiff : func (c context.Context , d * schema.ResourceDiff , meta interface {}) error {
36
- return validateVcsRepo (d )
36
+ if err := validateVcsRepo (d ); err != nil {
37
+ return err
38
+ }
39
+ return validateTestConfig (d )
37
40
},
38
41
Schema : map [string ]* schema.Schema {
39
42
"organization" : {
@@ -136,6 +139,19 @@ func resourceTFERegistryModule() *schema.Resource {
136
139
Type : schema .TypeBool ,
137
140
Optional : true ,
138
141
},
142
+ "agent_execution_mode" : {
143
+ Type : schema .TypeString ,
144
+ Optional : true ,
145
+ Computed : true ,
146
+ ValidateFunc : validation .StringInSlice (
147
+ []string {"agent" , "remote" },
148
+ false ,
149
+ ),
150
+ },
151
+ "agent_pool_id" : {
152
+ Type : schema .TypeString ,
153
+ Optional : true ,
154
+ },
139
155
},
140
156
},
141
157
},
@@ -197,6 +213,16 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d *
197
213
options .TestConfig = & tfe.RegistryModuleTestConfigOptions {
198
214
TestsEnabled : tfe .Bool (testsEnabled ),
199
215
}
216
+
217
+ if agentExecutionMode , ok := testConfig ["agent_execution_mode" ].(string ); ok && agentExecutionMode != "" {
218
+ mode := tfe .AgentExecutionMode (agentExecutionMode )
219
+ options .TestConfig .AgentExecutionMode = & mode
220
+ }
221
+
222
+ // Handle agent pool ID - only set if explicitly provided and not empty
223
+ if agentPoolID , ok := testConfig ["agent_pool_id" ].(string ); ok && agentPoolID != "" {
224
+ options .TestConfig .AgentPoolID = tfe .String (agentPoolID )
225
+ }
200
226
}
201
227
202
228
log .Printf ("[DEBUG] Create registry module from repository %s" , * options .VCSRepo .Identifier )
@@ -338,6 +364,21 @@ func resourceTFERegistryModuleUpdate(d *schema.ResourceData, meta interface{}) e
338
364
if testsEnabled , ok := testConfig ["tests_enabled" ].(bool ); ok {
339
365
options .TestConfig .TestsEnabled = tfe .Bool (testsEnabled )
340
366
}
367
+
368
+ if agentExecutionMode , ok := testConfig ["agent_execution_mode" ].(string ); ok && agentExecutionMode != "" {
369
+ mode := tfe .AgentExecutionMode (agentExecutionMode )
370
+ options .TestConfig .AgentExecutionMode = & mode
371
+ }
372
+
373
+ if agentPoolID , ok := testConfig ["agent_pool_id" ].(string ); ok {
374
+ if agentPoolID != "" {
375
+ options .TestConfig .AgentPoolID = tfe .String (agentPoolID )
376
+ } else if d .HasChange ("test_config.0.agent_pool_id" ) {
377
+ options .TestConfig .AgentPoolID = tfe .String ("" )
378
+ }
379
+ } else if d .HasChange ("test_config.0.agent_pool_id" ) {
380
+ options .TestConfig .AgentPoolID = tfe .String ("" )
381
+ }
341
382
}
342
383
343
384
err = retry .Retry (time .Duration (5 )* time .Minute , func () * retry.RetryError {
@@ -413,6 +454,13 @@ func resourceTFERegistryModuleRead(d *schema.ResourceData, meta interface{}) err
413
454
"tests_enabled" : registryModule .TestConfig .TestsEnabled ,
414
455
}
415
456
457
+ if registryModule .TestConfig .AgentExecutionMode != nil && * registryModule .TestConfig .AgentExecutionMode != "" {
458
+ testConfigValues ["agent_execution_mode" ] = string (* registryModule .TestConfig .AgentExecutionMode )
459
+ }
460
+
461
+ if registryModule .TestConfig .AgentPoolID != nil && * registryModule .TestConfig .AgentPoolID != "" {
462
+ testConfigValues ["agent_pool_id" ] = * registryModule .TestConfig .AgentPoolID
463
+ }
416
464
testConfig = append (testConfig , testConfigValues )
417
465
}
418
466
@@ -509,3 +557,29 @@ func validateVcsRepo(d *schema.ResourceDiff) error {
509
557
510
558
return nil
511
559
}
560
+
561
+ func validateTestConfig (d * schema.ResourceDiff ) error {
562
+ testConfig , ok := d .GetRawConfig ().AsValueMap ()["test_config" ]
563
+ if ! ok || testConfig .LengthInt () == 0 {
564
+ return nil
565
+ }
566
+
567
+ testConfigValue := testConfig .AsValueSlice ()[0 ]
568
+ agentExecutionModeValue := testConfigValue .GetAttr ("agent_execution_mode" )
569
+ agentPoolIDValue := testConfigValue .GetAttr ("agent_pool_id" )
570
+
571
+ if agentExecutionModeValue .IsNull () && agentPoolIDValue .IsNull () {
572
+ return nil
573
+ }
574
+
575
+ if ! agentExecutionModeValue .IsNull () && ! agentPoolIDValue .IsNull () {
576
+ executionMode := agentExecutionModeValue .AsString ()
577
+ agentPoolID := agentPoolIDValue .AsString ()
578
+
579
+ if executionMode == "remote" && agentPoolID != "" {
580
+ return fmt .Errorf ("agent_pool_id cannot be set when agent_execution_mode is 'remote'" )
581
+ }
582
+ }
583
+
584
+ return nil
585
+ }
0 commit comments