Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 12 additions & 0 deletions internal/provider/data_source_registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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,
},
Expand Down
21 changes: 21 additions & 0 deletions internal/provider/resource_tfe_registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)

Expand Down
115 changes: 115 additions & 0 deletions internal/provider/resource_tfe_registry_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 = "[email protected]"
}

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" {
Expand Down Expand Up @@ -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 = "[email protected]"
}

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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/cdktf/python/d/registry_module.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions website/docs/cdktf/python/r/registry_module.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/registry_module.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/registry_module.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading