Skip to content

Commit 8b7f711

Browse files
committed
Add source_directory and tag_prefix registry module support
1 parent 217fe8d commit 8b7f711

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

internal/provider/data_source_registry_module.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ type modelTFEVCSRepo struct {
9696
GHAInstallationID types.String `tfsdk:"github_app_installation_id"`
9797
RepositoryHTTPURL types.String `tfsdk:"repository_http_url"`
9898
ServiceProvider types.String `tfsdk:"service_provider"`
99+
SourceDirectory types.String `tfsdk:"source_directory"`
100+
TagPrefix types.String `tfsdk:"tag_prefix"`
99101
Tags types.Bool `tfsdk:"tags"`
100102
TagsRegex types.String `tfsdk:"tags_regex"`
101103
WebhookURL types.String `tfsdk:"webhook_url"`
@@ -127,6 +129,8 @@ func modelFromTFEVCSRepo(v *tfe.VCSRepo) modelTFEVCSRepo {
127129
GHAInstallationID: types.StringValue(v.GHAInstallationID),
128130
RepositoryHTTPURL: types.StringValue(v.RepositoryHTTPURL),
129131
ServiceProvider: types.StringValue(v.ServiceProvider),
132+
SourceDirectory: types.StringValue(v.SourceDirectory),
133+
TagPrefix: types.StringValue(v.TagPrefix),
130134
Tags: types.BoolValue(v.Tags),
131135
TagsRegex: types.StringValue(v.TagsRegex),
132136
WebhookURL: types.StringValue(v.WebhookURL),

internal/provider/data_source_workspace.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ func dataSourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error
373373
"oauth_token_id": workspace.VCSRepo.OAuthTokenID,
374374
"tags_regex": workspace.VCSRepo.TagsRegex,
375375
"github_app_installation_id": workspace.VCSRepo.GHAInstallationID,
376+
"source_directory": workspace.VCSRepo.SourceDirectory,
377+
"tag_prefix": workspace.VCSRepo.TagPrefix,
376378
}
377379
vcsRepo = append(vcsRepo, vcsConfig)
378380
}

internal/provider/resource_tfe_registry_module.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d *
189189
}
190190
}
191191

192+
tagPrefix, tagPrefixOk := vcsRepo["tag_prefix"].(string)
193+
sourceDirectory, sourceDirectoryOk := vcsRepo["source_directory"].(string)
194+
if tagPrefixOk && tagPrefix != "" {
195+
options.VCSRepo.TagPrefix = tfe.String(tagPrefix)
196+
}
197+
if sourceDirectoryOk && sourceDirectory != "" {
198+
options.VCSRepo.SourceDirectory = tfe.String(sourceDirectory)
199+
}
200+
192201
if vcsRepo["oauth_token_id"] != nil && vcsRepo["oauth_token_id"].(string) != "" {
193202
options.VCSRepo.OAuthTokenID = tfe.String(vcsRepo["oauth_token_id"].(string))
194203
}

internal/provider/resource_tfe_registry_module_test.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,56 @@ func TestAccTFERegistryModule_vcsRepoWithTags(t *testing.T) {
348348
})
349349
}
350350

351+
func TestAccTFERegistryModule_branchOnlyMonorepo(t *testing.T) {
352+
skipUnlessBeta(t)
353+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
354+
355+
resource.Test(t, resource.TestCase{
356+
PreCheck: func() {
357+
testAccPreCheck(t)
358+
testAccPreCheckTFERegistryModule(t)
359+
},
360+
ProtoV5ProviderFactories: testAccMuxedProviders,
361+
Steps: []resource.TestStep{
362+
{
363+
Config: testAccTFERegistryModule_branchOnlyMonorepo(rInt),
364+
Check: resource.ComposeTestCheckFunc(
365+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "publishing_mechanism", "branch"),
366+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "test_config.0.tests_enabled", strconv.FormatBool(false)),
367+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tags", strconv.FormatBool(false)),
368+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.branch", "main"),
369+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.source_directory", "src"),
370+
),
371+
},
372+
},
373+
})
374+
}
375+
376+
func TestAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(t *testing.T) {
377+
skipUnlessBeta(t)
378+
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
379+
380+
resource.Test(t, resource.TestCase{
381+
PreCheck: func() {
382+
testAccPreCheck(t)
383+
testAccPreCheckTFERegistryModule(t)
384+
},
385+
ProtoV5ProviderFactories: testAccMuxedProviders,
386+
Steps: []resource.TestStep{
387+
{
388+
Config: testAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(rInt),
389+
Check: resource.ComposeTestCheckFunc(
390+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "publishing_mechanism", "branch"),
391+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "test_config.0.tests_enabled", strconv.FormatBool(false)),
392+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tags", strconv.FormatBool(false)),
393+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.branch", "main"),
394+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.source_directory", "src"),
395+
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tag_prefix", "v"),
396+
},
397+
},
398+
})
399+
}
400+
351401
func TestAccTFERegistryModule_noCodeModule(t *testing.T) {
352402
skipIfEnterprise(t)
353403

@@ -1427,6 +1477,37 @@ resource "tfe_registry_module" "foobar" {
14271477
envGithubRegistryModuleIdentifer)
14281478
}
14291479

1480+
func testAccTFERegistryModule_branchOnlyMonorepo(rInt int) string {
1481+
return fmt.Sprintf(`
1482+
resource "tfe_organization" "foobar" {
1483+
name = "tst-terraform-%d"
1484+
1485+
}
1486+
1487+
resource "tfe_oauth_client" "foobar" {
1488+
organization = tfe_organization.foobar.name
1489+
api_url = "https://api.github.com"
1490+
http_url = "https://github.com"
1491+
oauth_token = "%s"
1492+
service_provider = "github"
1493+
}
1494+
1495+
resource "tfe_registry_module" "foobar" {
1496+
organization = tfe_organization.foobar.name
1497+
vcs_repo {
1498+
display_identifier = "%s"
1499+
identifier = "%s"
1500+
oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1501+
branch = "main"
1502+
source_directory = "src"
1503+
}
1504+
}`,
1505+
rInt,
1506+
envGithubToken,
1507+
envGithubRegistryModuleIdentifer,
1508+
envGithubRegistryModuleIdentifer)
1509+
}
1510+
14301511
func testAccTFERegistryModule_branchOnlyEmpty(rInt int) string {
14311512
return fmt.Sprintf(`
14321513
resource "tfe_organization" "foobar" {
@@ -1518,6 +1599,39 @@ resource "tfe_registry_module" "foobar" {
15181599
envGithubRegistryModuleIdentifer)
15191600
}
15201601

1602+
func testAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(rInt int) string {
1603+
return fmt.Sprintf(`
1604+
resource "tfe_organization" "foobar" {
1605+
name = "tst-terraform-%d"
1606+
1607+
}
1608+
1609+
resource "tfe_oauth_client" "foobar" {
1610+
organization = tfe_organization.foobar.name
1611+
api_url = "https://api.github.com"
1612+
http_url = "https://github.com"
1613+
oauth_token = "%s"
1614+
service_provider = "github"
1615+
}
1616+
1617+
resource "tfe_registry_module" "foobar" {
1618+
organization = tfe_organization.foobar.name
1619+
vcs_repo {
1620+
display_identifier = "%s"
1621+
identifier = "%s"
1622+
oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
1623+
branch = "main"
1624+
tags = false
1625+
tag_prefix = "v"
1626+
source_directory = "src"
1627+
}
1628+
}`,
1629+
rInt,
1630+
envGithubToken,
1631+
envGithubRegistryModuleIdentifer,
1632+
envGithubRegistryModuleIdentifer)
1633+
}
1634+
15211635
func testAccTFERegistryModule_GitHubApp(rInt int) string {
15221636
return fmt.Sprintf(`
15231637
resource "tfe_organization" "foobar" {

internal/provider/resource_tfe_workspace.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,16 @@ func resourceTFEWorkspaceCreate(d *schema.ResourceData, meta interface{}) error
511511
if branch, ok := vcsRepo["branch"].(string); ok && branch != "" {
512512
options.VCSRepo.Branch = tfe.String(branch)
513513
}
514+
515+
// Only set the source_directory if it is configured.
516+
if sourceDirectory, ok := vcsRepo["source_directory"].(string); ok && sourceDirectory != "" {
517+
options.VCSRepo.SourceDirectory = tfe.String(sourceDirectory)
518+
}
519+
520+
// Only set the tag_prefix if it is configured.
521+
if tagPrefix, ok := vcsRepo["tag_prefix"].(string); ok && tagPrefix != "" {
522+
options.VCSRepo.TagPrefix = tfe.String(tagPrefix)
523+
}
514524
}
515525

516526
for _, tagName := range d.Get("tag_names").(*schema.Set).List() {

0 commit comments

Comments
 (0)