Skip to content

Commit ad787cc

Browse files
authored
TF-26944 Add source_directory and tag_prefix registry module support (#1800)
1 parent adc5c69 commit ad787cc

8 files changed

+159
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
ENHANCEMENTS:
44
* `r/tfe_oauth_client`: The `oauth_token` attribute no longer triggers resource replacement unless combined with other replacement-triggering attributes. Use `terraform apply -replace` to force replacement. By @lilincmu [#1825](https://github.com/hashicorp/terraform-provider-tfe/pull/1825)
55

6+
FEATURES:
7+
* `r/tfe_registry_module`: Add `source_directory` and `tag_prefix` registry module support for private registry monorepository, which is a beta feature and not available to all users, by @jillirami ([#1800](https://github.com/hashicorp/terraform-provider-tfe/pull/1800))
8+
69
## v0.68.3
710

811
BUG FIXES:

internal/provider/data_source_registry_module.go

Lines changed: 12 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"`
@@ -111,6 +113,8 @@ func (m modelTFEVCSRepo) AttributeTypes() map[string]attr.Type {
111113
"github_app_installation_id": types.StringType,
112114
"repository_http_url": types.StringType,
113115
"service_provider": types.StringType,
116+
"source_directory": types.StringType,
117+
"tag_prefix": types.StringType,
114118
"tags": types.BoolType,
115119
"tags_regex": types.StringType,
116120
"webhook_url": types.StringType,
@@ -127,6 +131,8 @@ func modelFromTFEVCSRepo(v *tfe.VCSRepo) modelTFEVCSRepo {
127131
GHAInstallationID: types.StringValue(v.GHAInstallationID),
128132
RepositoryHTTPURL: types.StringValue(v.RepositoryHTTPURL),
129133
ServiceProvider: types.StringValue(v.ServiceProvider),
134+
SourceDirectory: types.StringValue(v.SourceDirectory),
135+
TagPrefix: types.StringValue(v.TagPrefix),
130136
Tags: types.BoolValue(v.Tags),
131137
TagsRegex: types.StringValue(v.TagsRegex),
132138
WebhookURL: types.StringValue(v.WebhookURL),
@@ -305,6 +311,12 @@ func (d *dataSourceTFERegistryModule) Schema(_ context.Context, _ datasource.Sch
305311
"service_provider": schema.StringAttribute{
306312
Computed: true,
307313
},
314+
"source_directory": schema.StringAttribute{
315+
Computed: true,
316+
},
317+
"tag_prefix": schema.StringAttribute{
318+
Computed: true,
319+
},
308320
"tags": schema.BoolAttribute{
309321
Computed: true,
310322
},

internal/provider/resource_tfe_registry_module.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ func resourceTFERegistryModule() *schema.Resource {
100100
Optional: true,
101101
Computed: true,
102102
},
103+
"source_directory": {
104+
Type: schema.TypeString,
105+
Optional: true,
106+
Computed: true,
107+
},
108+
"tag_prefix": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
Computed: true,
112+
},
103113
},
104114
},
105115
},
@@ -189,6 +199,15 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d *
189199
}
190200
}
191201

202+
tagPrefix, tagPrefixOk := vcsRepo["tag_prefix"].(string)
203+
sourceDirectory, sourceDirectoryOk := vcsRepo["source_directory"].(string)
204+
if tagPrefixOk && tagPrefix != "" {
205+
options.VCSRepo.TagPrefix = tfe.String(tagPrefix)
206+
}
207+
if sourceDirectoryOk && sourceDirectory != "" {
208+
options.VCSRepo.SourceDirectory = tfe.String(sourceDirectory)
209+
}
210+
192211
if vcsRepo["oauth_token_id"] != nil && vcsRepo["oauth_token_id"].(string) != "" {
193212
options.VCSRepo.OAuthTokenID = tfe.String(vcsRepo["oauth_token_id"].(string))
194213
}
@@ -401,6 +420,8 @@ func resourceTFERegistryModuleRead(d *schema.ResourceData, meta interface{}) err
401420
"display_identifier": registryModule.VCSRepo.DisplayIdentifier,
402421
"branch": registryModule.VCSRepo.Branch,
403422
"tags": registryModule.VCSRepo.Tags,
423+
"source_directory": registryModule.VCSRepo.SourceDirectory,
424+
"tag_prefix": registryModule.VCSRepo.TagPrefix,
404425
}
405426
vcsRepo = append(vcsRepo, vcsConfig)
406427

internal/provider/resource_tfe_registry_module_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,57 @@ 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+
}
401+
351402
func TestAccTFERegistryModule_noCodeModule(t *testing.T) {
352403
skipIfEnterprise(t)
353404

@@ -1427,6 +1478,37 @@ resource "tfe_registry_module" "foobar" {
14271478
envGithubRegistryModuleIdentifer)
14281479
}
14291480

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

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

website/docs/cdktf/python/d/registry_module.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ The `vcs_repo` block supports:
7676
* `github_app_installation_id` - The installation id of the Github App. This conflicts with `oauth_token_id` and can only be used if `oauth_token_id` is not used.
7777
* `branch` - The git branch used for publishing when using branch-based publishing for the registry module. When a `branch` is set, `tags` will be returned as `false`.
7878
* `tags` - Specifies whether tag based publishing is enabled for the registry module. When `tags` is set to `true`, the `branch` must be set to an empty value.
79+
* `source_directory` - (Optional) The path to the module configuration files within the VCS repository. This feature is currently in beta and is not available to all users.
80+
* `tag_prefix` - (Optional) The prefix to filter repository Git tags when using the tag-based publishing type in a repository that contains code for multiple modules. Without a prefix, HCP Terraform and Terraform Enterprise publish new versions for all modules with valid Git tags that use semantic versioning. This feature is currently in beta and is not available to all users.
7981

8082
The `permissions` block supports:
8183

website/docs/cdktf/python/r/registry_module.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ The `vcs_repo` block supports:
239239
* `github_app_installation_id` - (Optional) The installation id of the Github App. This conflicts with `oauth_token_id` and can only be used if `oauth_token_id` is not used.
240240
* `branch` - (Optional) The git branch used for publishing when using branch-based publishing for the registry module. When a `branch` is set, `tags` will be returned as `false`.
241241
* `tags` - (Optional) Specifies whether tag based publishing is enabled for the registry module. When `tags` is set to `true`, the `branch` must be set to an empty value.
242+
* `source_directory` - (Optional) The path to the module configuration files within the VCS repository. This feature is currently in beta and is not available to all users.
243+
* `tag_prefix` - (Optional) The prefix to filter repository Git tags when using the tag-based publishing type in a repository that contains code for multiple modules. Without a prefix, HCP Terraform and Terraform Enterprise publish new versions for all modules with valid Git tags that use semantic versioning. This feature is currently in beta and is not available to all users.
242244

243245
## Attributes Reference
244246

website/docs/d/registry_module.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The `vcs_repo` block supports:
6363
* `github_app_installation_id` - The installation id of the Github App. This conflicts with `oauth_token_id` and can only be used if `oauth_token_id` is not used.
6464
* `branch` - The git branch used for publishing when using branch-based publishing for the registry module. When a `branch` is set, `tags` will be returned as `false`.
6565
* `tags` - Specifies whether tag based publishing is enabled for the registry module. When `tags` is set to `true`, the `branch` must be set to an empty value.
66+
* `source_directory` - (Optional) The path to the module configuration files within the VCS repository. This feature is currently in beta and is not available to all users.
67+
* `tag_prefix` - (Optional) The prefix to filter repository Git tags when using the tag-based publishing type in a repository that contains code for multiple modules. Without a prefix, HCP Terraform and Terraform Enterprise publish new versions for all modules with valid Git tags that use semantic versioning. This feature is currently in beta and is not available to all users.
6668

6769
The `permissions` block supports:
6870

website/docs/r/registry_module.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ The `vcs_repo` block supports:
171171
* `github_app_installation_id` - (Optional) The installation id of the Github App. This conflicts with `oauth_token_id` and can only be used if `oauth_token_id` is not used.
172172
* `branch` - (Optional) The git branch used for publishing when using branch-based publishing for the registry module. When a `branch` is set, `tags` will be returned as `false`.
173173
* `tags` - (Optional) Specifies whether tag based publishing is enabled for the registry module. When `tags` is set to `true`, the `branch` must be set to an empty value.
174+
* `source_directory` - (Optional) The path to the module configuration files within the VCS repository. This feature is currently in beta and is not available to all users.
175+
* `tag_prefix` - (Optional) The prefix to filter repository Git tags when using the tag-based publishing type in a repository that contains code for multiple modules. Without a prefix, HCP Terraform and Terraform Enterprise publish new versions for all modules with valid Git tags that use semantic versioning. This feature is currently in beta and is not available to all users.
174176

175177
## Attributes Reference
176178

0 commit comments

Comments
 (0)