@@ -17,7 +17,7 @@ import (
17
17
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
18
18
)
19
19
20
- func TestAccTFERegistryModule_vcs (t * testing.T ) {
20
+ func TestAccTFERegistryModule_vcsBasic (t * testing.T ) {
21
21
registryModule := & tfe.RegistryModule {}
22
22
rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
23
23
orgName := fmt .Sprintf ("tst-terraform-%d" , rInt )
@@ -38,7 +38,7 @@ func TestAccTFERegistryModule_vcs(t *testing.T) {
38
38
CheckDestroy : testAccCheckTFERegistryModuleDestroy ,
39
39
Steps : []resource.TestStep {
40
40
{
41
- Config : testAccTFERegistryModule_vcs (rInt ),
41
+ Config : testAccTFERegistryModule_vcsBasic (rInt ),
42
42
Check : resource .ComposeTestCheckFunc (
43
43
testAccCheckTFERegistryModuleExists (
44
44
"tfe_registry_module.foobar" ,
@@ -300,7 +300,7 @@ func TestAccTFERegistryModule_publicRegistryModule(t *testing.T) {
300
300
})
301
301
}
302
302
303
- func TestAccTFERegistryModule_vcsRepoWithTagField (t * testing.T ) {
303
+ func TestAccTFERegistryModule_branchOnly (t * testing.T ) {
304
304
skipUnlessBeta (t )
305
305
rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
306
306
@@ -312,7 +312,31 @@ func TestAccTFERegistryModule_vcsRepoWithTagField(t *testing.T) {
312
312
Providers : testAccProviders ,
313
313
Steps : []resource.TestStep {
314
314
{
315
- Config : testAccTFERegistryModule_vcsRepoWithFalseTagField (rInt ),
315
+ Config : testAccTFERegistryModule_branchOnly (rInt ),
316
+ Check : resource .ComposeTestCheckFunc (
317
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "publishing_mechanism" , "branch" ),
318
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "test_config.0.tests_enabled" , strconv .FormatBool (false )),
319
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "vcs_repo.0.tags" , strconv .FormatBool (false )),
320
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "vcs_repo.0.branch" , "main" ),
321
+ ),
322
+ },
323
+ },
324
+ })
325
+ }
326
+
327
+ func TestAccTFERegistryModule_vcsRepoWithTags (t * testing.T ) {
328
+ skipUnlessBeta (t )
329
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
330
+
331
+ resource .Test (t , resource.TestCase {
332
+ PreCheck : func () {
333
+ testAccPreCheck (t )
334
+ testAccPreCheckTFERegistryModule (t )
335
+ },
336
+ Providers : testAccProviders ,
337
+ Steps : []resource.TestStep {
338
+ {
339
+ Config : testAccTFERegistryModule_vcsRepoWithFalseTags (rInt ),
316
340
Check : resource .ComposeTestCheckFunc (
317
341
resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "publishing_mechanism" , "branch" ),
318
342
resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "test_config.0.tests_enabled" , strconv .FormatBool (false )),
@@ -390,7 +414,7 @@ func TestAccTFERegistryModuleImport_vcsPrivateRMDeprecatedFormat(t *testing.T) {
390
414
CheckDestroy : testAccCheckTFERegistryModuleDestroy ,
391
415
Steps : []resource.TestStep {
392
416
{
393
- Config : testAccTFERegistryModule_vcs (rInt ),
417
+ Config : testAccTFERegistryModule_vcsWithTagsTrue (rInt ),
394
418
},
395
419
{
396
420
ResourceName : "tfe_registry_module.foobar" ,
@@ -414,7 +438,7 @@ func TestAccTFERegistryModuleImport_vcsPrivateRMRecommendedFormat(t *testing.T)
414
438
CheckDestroy : testAccCheckTFERegistryModuleDestroy ,
415
439
Steps : []resource.TestStep {
416
440
{
417
- Config : testAccTFERegistryModule_vcs (rInt ),
441
+ Config : testAccTFERegistryModule_vcsWithTagsTrue (rInt ),
418
442
},
419
443
{
420
444
ResourceName : "tfe_registry_module.foobar" ,
@@ -485,6 +509,30 @@ func TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranch(t
485
509
})
486
510
}
487
511
512
+ func TestAccTFERegistryModule_branchOnlyEmpty (t * testing.T ) {
513
+ skipUnlessBeta (t )
514
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
515
+
516
+ resource .Test (t , resource.TestCase {
517
+ PreCheck : func () {
518
+ testAccPreCheck (t )
519
+ testAccPreCheckTFERegistryModule (t )
520
+ },
521
+ Providers : testAccProviders ,
522
+ Steps : []resource.TestStep {
523
+ {
524
+ Config : testAccTFERegistryModule_branchOnlyEmpty (rInt ),
525
+ Check : resource .ComposeTestCheckFunc (
526
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "publishing_mechanism" , "git_tag" ),
527
+ resource .TestCheckNoResourceAttr ("tfe_registry_module.foobar" , "test_config.0" ),
528
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "vcs_repo.0.tags" , strconv .FormatBool (true )),
529
+ resource .TestCheckResourceAttr ("tfe_registry_module.foobar" , "vcs_repo.0.branch" , "" ),
530
+ ),
531
+ },
532
+ },
533
+ })
534
+ }
535
+
488
536
func TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranchWithTests (t * testing.T ) {
489
537
rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
490
538
@@ -621,6 +669,25 @@ func TestAccTFERegistryModule_invalidTestConfigOnUpdate(t *testing.T) {
621
669
})
622
670
}
623
671
672
+ func TestAccTFERegistryModule_vcsTagsOnlyFalse (t * testing.T ) {
673
+ skipUnlessBeta (t )
674
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
675
+
676
+ resource .Test (t , resource.TestCase {
677
+ PreCheck : func () {
678
+ testAccPreCheck (t )
679
+ testAccPreCheckTFERegistryModule (t )
680
+ },
681
+ Providers : testAccProviders ,
682
+ Steps : []resource.TestStep {
683
+ {
684
+ Config : testAccTFERegistryModule_vcsTagsOnlyFalse (rInt ),
685
+ ExpectError : regexp .MustCompile (`branch must be provided when tags is set to false` ),
686
+ },
687
+ },
688
+ })
689
+ }
690
+
624
691
func TestAccTFERegistryModule_branchAndInvalidTagsOnCreate (t * testing.T ) {
625
692
rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
626
693
@@ -1035,7 +1102,7 @@ func getRegistryModuleProvider() string {
1035
1102
return strings .SplitN (getRegistryModuleRepository (), "-" , 3 )[1 ]
1036
1103
}
1037
1104
1038
- func testAccTFERegistryModule_vcs (rInt int ) string {
1105
+ func testAccTFERegistryModule_vcsWithTagsTrue (rInt int ) string {
1039
1106
return fmt .Sprintf (`
1040
1107
resource "tfe_organization" "foobar" {
1041
1108
name = "tst-terraform-%d"
@@ -1277,6 +1344,125 @@ resource "tfe_registry_module" "foobar" {
1277
1344
envGithubRegistryModuleIdentifer )
1278
1345
}
1279
1346
1347
+ func testAccTFERegistryModule_vcsBasic (rInt int ) string {
1348
+ return fmt .Sprintf (`
1349
+ resource "tfe_organization" "foobar" {
1350
+ name = "tst-terraform-%d"
1351
+
1352
+ }
1353
+
1354
+ resource "tfe_oauth_client" "foobar" {
1355
+ organization = tfe_organization.foobar.name
1356
+ api_url = "https://api.github.com"
1357
+ http_url = "https://github.com"
1358
+ oauth_token = "%s"
1359
+ service_provider = "github"
1360
+ }
1361
+
1362
+ resource "tfe_registry_module" "foobar" {
1363
+ organization = tfe_organization.foobar.name
1364
+ vcs_repo {
1365
+ display_identifier = "%s"
1366
+ identifier = "%s"
1367
+ oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1368
+ }
1369
+ }` ,
1370
+ rInt ,
1371
+ envGithubToken ,
1372
+ envGithubRegistryModuleIdentifer ,
1373
+ envGithubRegistryModuleIdentifer )
1374
+ }
1375
+
1376
+ func testAccTFERegistryModule_vcsTagsOnlyFalse (rInt int ) string {
1377
+ return fmt .Sprintf (`
1378
+ resource "tfe_organization" "foobar" {
1379
+ name = "tst-terraform-%d"
1380
+
1381
+ }
1382
+
1383
+ resource "tfe_oauth_client" "foobar" {
1384
+ organization = tfe_organization.foobar.name
1385
+ api_url = "https://api.github.com"
1386
+ http_url = "https://github.com"
1387
+ oauth_token = "%s"
1388
+ service_provider = "github"
1389
+ }
1390
+
1391
+ resource "tfe_registry_module" "foobar" {
1392
+ organization = tfe_organization.foobar.name
1393
+ vcs_repo {
1394
+ display_identifier = "%s"
1395
+ identifier = "%s"
1396
+ oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1397
+ tags = false
1398
+ }
1399
+ }` ,
1400
+ rInt ,
1401
+ envGithubToken ,
1402
+ envGithubRegistryModuleIdentifer ,
1403
+ envGithubRegistryModuleIdentifer )
1404
+ }
1405
+
1406
+ func testAccTFERegistryModule_branchOnly (rInt int ) string {
1407
+ return fmt .Sprintf (`
1408
+ resource "tfe_organization" "foobar" {
1409
+ name = "tst-terraform-%d"
1410
+
1411
+ }
1412
+
1413
+ resource "tfe_oauth_client" "foobar" {
1414
+ organization = tfe_organization.foobar.name
1415
+ api_url = "https://api.github.com"
1416
+ http_url = "https://github.com"
1417
+ oauth_token = "%s"
1418
+ service_provider = "github"
1419
+ }
1420
+
1421
+ resource "tfe_registry_module" "foobar" {
1422
+ organization = tfe_organization.foobar.name
1423
+ vcs_repo {
1424
+ display_identifier = "%s"
1425
+ identifier = "%s"
1426
+ oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1427
+ branch = "main"
1428
+ }
1429
+ }` ,
1430
+ rInt ,
1431
+ envGithubToken ,
1432
+ envGithubRegistryModuleIdentifer ,
1433
+ envGithubRegistryModuleIdentifer )
1434
+ }
1435
+
1436
+ func testAccTFERegistryModule_branchOnlyEmpty (rInt int ) string {
1437
+ return fmt .Sprintf (`
1438
+ resource "tfe_organization" "foobar" {
1439
+ name = "tst-terraform-%d"
1440
+
1441
+ }
1442
+
1443
+ resource "tfe_oauth_client" "foobar" {
1444
+ organization = tfe_organization.foobar.name
1445
+ api_url = "https://api.github.com"
1446
+ http_url = "https://github.com"
1447
+ oauth_token = "%s"
1448
+ service_provider = "github"
1449
+ }
1450
+
1451
+ resource "tfe_registry_module" "foobar" {
1452
+ organization = tfe_organization.foobar.name
1453
+ vcs_repo {
1454
+ display_identifier = "%s"
1455
+ identifier = "%s"
1456
+ oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1457
+ branch = ""
1458
+ }
1459
+ }` ,
1460
+ rInt ,
1461
+ envGithubToken ,
1462
+ envGithubRegistryModuleIdentifer ,
1463
+ envGithubRegistryModuleIdentifer )
1464
+ }
1465
+
1280
1466
func testAccTFERegistryModule_vcsTags (rInt int ) string {
1281
1467
return fmt .Sprintf (`
1282
1468
resource "tfe_organization" "foobar" {
@@ -1307,7 +1493,7 @@ resource "tfe_registry_module" "foobar" {
1307
1493
envGithubRegistryModuleIdentifer ,
1308
1494
envGithubRegistryModuleIdentifer )
1309
1495
}
1310
- func testAccTFERegistryModule_vcsRepoWithFalseTagField (rInt int ) string {
1496
+ func testAccTFERegistryModule_vcsRepoWithFalseTags (rInt int ) string {
1311
1497
return fmt .Sprintf (`
1312
1498
resource "tfe_organization" "foobar" {
1313
1499
name = "tst-terraform-%d"
0 commit comments