Skip to content

Commit 3d00b62

Browse files
authored
Merge branch 'main' into kelsi-hoyle/TF-24744/arm-toolversion-support
2 parents 2dadead + 6923355 commit 3d00b62

15 files changed

+216
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
FEATURES:
44

5+
* `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))
56
* `r/tfe_terraform_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
67
* `r/tfe_opa_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
78
* `r/tfe_sentinel_version`: Adds support for specifying architecture-specific binaries using the `archs` attribute, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
89

9-
1010
DEPRECATIONS:
1111

1212
* `r/tfe_terraform_version`: The `url` and `sha` attributes are deprecated and will be removed in a future version. Use the `archs` attribute to specify architecture-specific binaries going forward, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
1313
* `r/tfe_opa_version`: The `url` and `sha` attributes are deprecated and will be removed in a future version. Use the `archs` attribute to specify architecture-specific binaries going forward, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
1414
* `r/tfe_sentinel_version`: The `url` and `sha` attributes are deprecated and will be removed in a future version. Use the `archs` attribute to specify architecture-specific binaries going forward, by @kelsi-hoyle [1762](https://github.com/hashicorp/terraform-provider-tfe/pull/1762)
15+
* `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)
16+
* `r/tfe_test_variable`: Add missing argument reference and attributes documentation ([#1625](https://github.com/hashicorp/terraform-provider-tfe/issues/1625))
1517

1618
## v0.68.3
1719

1820
BUG FIXES:
21+
1922
* `r/tfe_notification_configuration`: update url attribute to be sensitive, by @jillirami [#1799](https://github.com/hashicorp/terraform-provider-tfe/pull/1799)
23+
* `d/tfe_project`: fixes: 'duplicate set element' error, as workspaces can appear multiple times in get /workspaces, by @lewis-catley [#1817](https://github.com/hashicorp/terraform-provider-tfe/pull/1817)
2024
* `r/tfe_workspace`: fixed documentation Example Usages to use the `tfe_organization.test-organization.name` as organization name
2125
* `r/tfe_workspace_run`: fixed documentation Example Usages to use the `tfe_organization.test-organization.name` as organization name
2226

internal/provider/data_source_project.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type modelDataSourceTFEProject struct {
3939
EffectiveTags types.Map `tfsdk:"effective_tags"`
4040
}
4141

42-
func modelDataSourceFromTFEProject(p *tfe.Project, workspaceIDs, workspaceNames []string, effectiveTags []*tfe.EffectiveTagBinding) (modelDataSourceTFEProject, diag.Diagnostics) {
42+
func modelDataSourceFromTFEProject(p *tfe.Project, workspaces map[string]string, effectiveTags []*tfe.EffectiveTagBinding) (modelDataSourceTFEProject, diag.Diagnostics) {
4343
m := modelDataSourceTFEProject{
4444
ID: types.StringValue(p.ID),
4545
Name: types.StringValue(p.Name),
@@ -48,9 +48,9 @@ func modelDataSourceFromTFEProject(p *tfe.Project, workspaceIDs, workspaceNames
4848
}
4949

5050
var wids, wnames []attr.Value
51-
for w := range workspaceIDs {
52-
wids = append(wids, types.StringValue(workspaceIDs[w]))
53-
wnames = append(wnames, types.StringValue(workspaceNames[w]))
51+
for workspaceID, workspaceName := range workspaces {
52+
wids = append(wids, types.StringValue(workspaceID))
53+
wnames = append(wnames, types.StringValue(workspaceName))
5454
}
5555
m.WorkspaceIDs = types.SetValueMust(types.StringType, wids)
5656
m.WorkspaceNames = types.SetValueMust(types.StringType, wnames)
@@ -187,8 +187,9 @@ func (d *dataSourceTFEProject) Read(ctx context.Context, req datasource.ReadRequ
187187
ProjectID: proj.ID,
188188
}
189189

190-
var workspaceIDs []string
191-
var workspaceNames []string
190+
// Store GET /workspaces response in a map to ensure uniqueness
191+
// key: workspaceID, value: workspaceName
192+
workspaces := make(map[string]string)
192193
for {
193194
wl, err := d.config.Client.Workspaces.List(ctx, organization, readOptions)
194195
if err != nil {
@@ -197,8 +198,7 @@ func (d *dataSourceTFEProject) Read(ctx context.Context, req datasource.ReadRequ
197198
}
198199

199200
for _, workspace := range wl.Items {
200-
workspaceIDs = append(workspaceIDs, workspace.ID)
201-
workspaceNames = append(workspaceNames, workspace.Name)
201+
workspaces[workspace.ID] = workspace.Name
202202
}
203203

204204
// Exit the loop when we've seen all pages.
@@ -221,7 +221,7 @@ func (d *dataSourceTFEProject) Read(ctx context.Context, req datasource.ReadRequ
221221
effectiveBindings = []*tfe.EffectiveTagBinding{}
222222
}
223223

224-
m, diags := modelDataSourceFromTFEProject(proj, workspaceIDs, workspaceNames, effectiveBindings)
224+
m, diags := modelDataSourceFromTFEProject(proj, workspaces, effectiveBindings)
225225
if diags.HasError() {
226226
resp.Diagnostics.Append(diags...)
227227
return

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/helper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ func createBusinessOrganization(t *testing.T, client *tfe.Client) (*tfe.Organiza
6666
return org, orgCleanup
6767
}
6868

69-
func createPlusOrganization(t *testing.T, client *tfe.Client) (*tfe.Organization, func()) {
69+
func createStandardOrganization(t *testing.T, client *tfe.Client) (*tfe.Organization, func()) {
7070
org, orgCleanup := createOrganization(t, client, tfe.OrganizationCreateOptions{
7171
Name: tfe.String("tst-" + randomString(t)),
7272
Email: tfe.String(fmt.Sprintf("%[email protected]", randomString(t))),
7373
})
7474

75-
newSubscriptionUpdater(org).WithPlusEntitlementPlan().Update(t)
75+
newSubscriptionUpdater(org).WithStandardEntitlementPlan().Update(t)
7676

7777
return org, orgCleanup
7878
}

internal/provider/resource_tfe_oauth_client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func resourceTFEOAuthClient() *schema.Resource {
6363
Type: schema.TypeString,
6464
Optional: true,
6565
Sensitive: true,
66-
ForceNew: true,
6766
},
6867

6968
"private_key": {

internal/provider/resource_tfe_oauth_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func TestAccTFEOAuthClient_updateOAuthTokenID(t *testing.T) {
172172
testAccCheckTFEOAuthClientExists("tfe_oauth_client.foobar", oc),
173173
resource.TestCheckResourceAttrSet("tfe_oauth_client.foobar", "oauth_token_id"),
174174
func(s *terraform.State) error {
175-
if initialOAuthTokenID == oc.OAuthTokens[0].ID {
176-
return fmt.Errorf("oauth_token_id did not change")
175+
if initialOAuthTokenID != oc.OAuthTokens[0].ID {
176+
return fmt.Errorf("oauth_token_id changed")
177177
}
178178
return nil
179179
},

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" {

0 commit comments

Comments
 (0)