diff --git a/CHANGELOG.md b/CHANGELOG.md index 977653a9b..1bb5216ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased +FEATURES: +* `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)) + ## v0.68.3 BUG FIXES: diff --git a/internal/provider/data_source_registry_module.go b/internal/provider/data_source_registry_module.go index af249d356..cf0237cff 100644 --- a/internal/provider/data_source_registry_module.go +++ b/internal/provider/data_source_registry_module.go @@ -96,6 +96,8 @@ type modelTFEVCSRepo struct { GHAInstallationID types.String `tfsdk:"github_app_installation_id"` RepositoryHTTPURL types.String `tfsdk:"repository_http_url"` ServiceProvider types.String `tfsdk:"service_provider"` + SourceDirectory types.String `tfsdk:"source_directory"` + TagPrefix types.String `tfsdk:"tag_prefix"` Tags types.Bool `tfsdk:"tags"` TagsRegex types.String `tfsdk:"tags_regex"` WebhookURL types.String `tfsdk:"webhook_url"` @@ -111,6 +113,8 @@ func (m modelTFEVCSRepo) AttributeTypes() map[string]attr.Type { "github_app_installation_id": types.StringType, "repository_http_url": types.StringType, "service_provider": types.StringType, + "source_directory": types.StringType, + "tag_prefix": types.StringType, "tags": types.BoolType, "tags_regex": types.StringType, "webhook_url": types.StringType, @@ -127,6 +131,8 @@ func modelFromTFEVCSRepo(v *tfe.VCSRepo) modelTFEVCSRepo { GHAInstallationID: types.StringValue(v.GHAInstallationID), RepositoryHTTPURL: types.StringValue(v.RepositoryHTTPURL), ServiceProvider: types.StringValue(v.ServiceProvider), + SourceDirectory: types.StringValue(v.SourceDirectory), + TagPrefix: types.StringValue(v.TagPrefix), Tags: types.BoolValue(v.Tags), TagsRegex: types.StringValue(v.TagsRegex), WebhookURL: types.StringValue(v.WebhookURL), @@ -305,6 +311,12 @@ func (d *dataSourceTFERegistryModule) Schema(_ context.Context, _ datasource.Sch "service_provider": schema.StringAttribute{ Computed: true, }, + "source_directory": schema.StringAttribute{ + Computed: true, + }, + "tag_prefix": schema.StringAttribute{ + Computed: true, + }, "tags": schema.BoolAttribute{ Computed: true, }, diff --git a/internal/provider/resource_tfe_registry_module.go b/internal/provider/resource_tfe_registry_module.go index b67e8a782..582b60d26 100644 --- a/internal/provider/resource_tfe_registry_module.go +++ b/internal/provider/resource_tfe_registry_module.go @@ -100,6 +100,16 @@ func resourceTFERegistryModule() *schema.Resource { Optional: true, Computed: true, }, + "source_directory": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "tag_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, }, }, }, @@ -189,6 +199,15 @@ func resourceTFERegistryModuleCreateWithVCS(v interface{}, meta interface{}, d * } } + tagPrefix, tagPrefixOk := vcsRepo["tag_prefix"].(string) + sourceDirectory, sourceDirectoryOk := vcsRepo["source_directory"].(string) + if tagPrefixOk && tagPrefix != "" { + options.VCSRepo.TagPrefix = tfe.String(tagPrefix) + } + if sourceDirectoryOk && sourceDirectory != "" { + options.VCSRepo.SourceDirectory = tfe.String(sourceDirectory) + } + if vcsRepo["oauth_token_id"] != nil && vcsRepo["oauth_token_id"].(string) != "" { options.VCSRepo.OAuthTokenID = tfe.String(vcsRepo["oauth_token_id"].(string)) } @@ -401,6 +420,8 @@ func resourceTFERegistryModuleRead(d *schema.ResourceData, meta interface{}) err "display_identifier": registryModule.VCSRepo.DisplayIdentifier, "branch": registryModule.VCSRepo.Branch, "tags": registryModule.VCSRepo.Tags, + "source_directory": registryModule.VCSRepo.SourceDirectory, + "tag_prefix": registryModule.VCSRepo.TagPrefix, } vcsRepo = append(vcsRepo, vcsConfig) diff --git a/internal/provider/resource_tfe_registry_module_test.go b/internal/provider/resource_tfe_registry_module_test.go index f12954c84..4056a44ef 100644 --- a/internal/provider/resource_tfe_registry_module_test.go +++ b/internal/provider/resource_tfe_registry_module_test.go @@ -348,6 +348,57 @@ func TestAccTFERegistryModule_vcsRepoWithTags(t *testing.T) { }) } +func TestAccTFERegistryModule_branchOnlyMonorepo(t *testing.T) { + skipUnlessBeta(t) + rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccPreCheckTFERegistryModule(t) + }, + ProtoV5ProviderFactories: testAccMuxedProviders, + Steps: []resource.TestStep{ + { + Config: testAccTFERegistryModule_branchOnlyMonorepo(rInt), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "publishing_mechanism", "branch"), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "test_config.0.tests_enabled", strconv.FormatBool(false)), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tags", strconv.FormatBool(false)), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.branch", "main"), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.source_directory", "src"), + ), + }, + }, + }) +} + +func TestAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(t *testing.T) { + skipUnlessBeta(t) + rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccPreCheckTFERegistryModule(t) + }, + ProtoV5ProviderFactories: testAccMuxedProviders, + Steps: []resource.TestStep{ + { + Config: testAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(rInt), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "publishing_mechanism", "branch"), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "test_config.0.tests_enabled", strconv.FormatBool(false)), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tags", strconv.FormatBool(false)), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.branch", "main"), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.source_directory", "src"), + resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tag_prefix", "v"), + ), + }, + }, + }) +} + func TestAccTFERegistryModule_noCodeModule(t *testing.T) { skipIfEnterprise(t) @@ -1427,6 +1478,37 @@ resource "tfe_registry_module" "foobar" { envGithubRegistryModuleIdentifer) } +func testAccTFERegistryModule_branchOnlyMonorepo(rInt int) string { + return fmt.Sprintf(` +resource "tfe_organization" "foobar" { + name = "tst-terraform-%d" + email = "admin@company.com" +} + +resource "tfe_oauth_client" "foobar" { + organization = tfe_organization.foobar.name + api_url = "https://api.github.com" + http_url = "https://github.com" + oauth_token = "%s" + service_provider = "github" +} + +resource "tfe_registry_module" "foobar" { + organization = tfe_organization.foobar.name + vcs_repo { + display_identifier = "%s" + identifier = "%s" + oauth_token_id = tfe_oauth_client.foobar.oauth_token_id + branch = "main" + source_directory = "src" + } +}`, + rInt, + envGithubToken, + envGithubRegistryModuleIdentifer, + envGithubRegistryModuleIdentifer) +} + func testAccTFERegistryModule_branchOnlyEmpty(rInt int) string { return fmt.Sprintf(` resource "tfe_organization" "foobar" { @@ -1518,6 +1600,39 @@ resource "tfe_registry_module" "foobar" { envGithubRegistryModuleIdentifer) } +func testAccTFERegistryModule_vcsRepoWithTagPrefixMonorepo(rInt int) string { + return fmt.Sprintf(` +resource "tfe_organization" "foobar" { + name = "tst-terraform-%d" + email = "admin@company.com" +} + +resource "tfe_oauth_client" "foobar" { + organization = tfe_organization.foobar.name + api_url = "https://api.github.com" + http_url = "https://github.com" + oauth_token = "%s" + service_provider = "github" +} + +resource "tfe_registry_module" "foobar" { + organization = tfe_organization.foobar.name + vcs_repo { + display_identifier = "%s" + identifier = "%s" + oauth_token_id = tfe_oauth_client.foobar.oauth_token_id + branch = "main" + tags = false + tag_prefix = "v" + source_directory = "src" + } +}`, + rInt, + envGithubToken, + envGithubRegistryModuleIdentifer, + envGithubRegistryModuleIdentifer) +} + func testAccTFERegistryModule_GitHubApp(rInt int) string { return fmt.Sprintf(` resource "tfe_organization" "foobar" { diff --git a/website/docs/cdktf/python/d/registry_module.html.markdown b/website/docs/cdktf/python/d/registry_module.html.markdown index 84d5a68c3..246596c27 100644 --- a/website/docs/cdktf/python/d/registry_module.html.markdown +++ b/website/docs/cdktf/python/d/registry_module.html.markdown @@ -76,6 +76,8 @@ The `vcs_repo` block supports: * `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. * `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`. * `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. +* `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. +* `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. The `permissions` block supports: diff --git a/website/docs/cdktf/python/r/registry_module.html.markdown b/website/docs/cdktf/python/r/registry_module.html.markdown index 006655900..e63982d02 100644 --- a/website/docs/cdktf/python/r/registry_module.html.markdown +++ b/website/docs/cdktf/python/r/registry_module.html.markdown @@ -239,6 +239,8 @@ The `vcs_repo` block supports: * `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. * `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`. * `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. +* `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. +* `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. ## Attributes Reference diff --git a/website/docs/d/registry_module.html.markdown b/website/docs/d/registry_module.html.markdown index b5ce019b3..f86e612c4 100644 --- a/website/docs/d/registry_module.html.markdown +++ b/website/docs/d/registry_module.html.markdown @@ -63,6 +63,8 @@ The `vcs_repo` block supports: * `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. * `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`. * `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. +* `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. +* `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. The `permissions` block supports: diff --git a/website/docs/r/registry_module.html.markdown b/website/docs/r/registry_module.html.markdown index 32a365ed1..8d3720fd0 100644 --- a/website/docs/r/registry_module.html.markdown +++ b/website/docs/r/registry_module.html.markdown @@ -171,6 +171,8 @@ The `vcs_repo` block supports: * `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. * `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`. * `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. +* `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. +* `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. ## Attributes Reference