Skip to content

Commit 750b687

Browse files
authored
Merge branch 'main' into private-vcs/api-support
2 parents 83e97f8 + ef4d68e commit 750b687

File tree

9 files changed

+81
-10
lines changed

9 files changed

+81
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
node-version: 16
6868

6969
- name: Download artifacts
70-
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
70+
uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # v4.1.3
7171

7272
- name: Install junit-report-merger
7373
run: npm install -g junit-report-merger

.github/workflows/create-release-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
run: npm install -g [email protected]
9090

9191
- name: Download artifacts
92-
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
92+
uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # v4.1.3
9393
with:
9494
name: terraform-provider-tfe
9595

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## UNRELEASED
2+
3+
FEATURES:
4+
* `r/tfe_workspace`: Add `ignore_additional_tag_names` which explicitly ignores `tag_names` _not_ defined by config so they will not be overwritten by the configured tags, by @brandonc and @mbillow [1254](https://github.com/hashicorp/terraform-provider-tfe/pull/1254)
5+
16
## v0.52.0
27

38
FEATURES:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/hashicorp/go-multierror v1.1.1 // indirect
1313
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
1414
github.com/hashicorp/go-slug v0.14.0
15-
github.com/hashicorp/go-tfe v1.44.0
15+
github.com/hashicorp/go-tfe v1.45.0
1616
github.com/hashicorp/go-version v1.6.0
1717
github.com/hashicorp/hcl v1.0.0
1818
github.com/hashicorp/hcl/v2 v2.19.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT
7171
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
7272
github.com/hashicorp/go-slug v0.14.0 h1:/aZdUDjR74TSlsQp3hA9nqhCQkQHAUr2jjtuUfWqI9E=
7373
github.com/hashicorp/go-slug v0.14.0/go.mod h1:THWVTAXwJEinbsp4/bBRcmbaO5EYNLTqxbG4tZ3gCYQ=
74-
github.com/hashicorp/go-tfe v1.44.0 h1:eQ9n2Ecfel6O5j03UW6B9LNsM1x6KbHErsjwSd9BLmg=
75-
github.com/hashicorp/go-tfe v1.44.0/go.mod h1:3ZGX+wxeyp/JnP8qEZo8m3s0ggJ7H+L2BvJRpkRdtVU=
74+
github.com/hashicorp/go-tfe v1.45.0 h1:WCiQWUV7n1Fq/pKA9C3rhcSmUtSPTYBtE1kIJ9U0NSU=
75+
github.com/hashicorp/go-tfe v1.45.0/go.mod h1:GRvhVp0mlNK/msPAvdeubWnV57avNoCmeaetcmvUyHY=
7676
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
7777
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
7878
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

internal/provider/resource_tfe_notification_configuration_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,6 @@ func testAccCheckTFENotificationConfigurationAttributesSlack(notificationConfigu
703703
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
704704
}
705705

706-
if notificationConfiguration.URL != "http://example.com" {
707-
return fmt.Errorf("Bad URL: %s", notificationConfiguration.URL)
708-
}
709-
710706
return nil
711707
}
712708
}

internal/provider/resource_tfe_workspace.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func resourceTFEWorkspace() *schema.Resource {
209209
Elem: &schema.Schema{Type: schema.TypeString},
210210
},
211211

212+
"ignore_additional_tag_names": {
213+
Type: schema.TypeBool,
214+
Optional: true,
215+
},
216+
212217
"terraform_version": {
213218
Type: schema.TypeString,
214219
Optional: true,
@@ -529,8 +534,11 @@ func resourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
529534
d.Set("agent_pool_id", agentPoolID)
530535

531536
var tagNames []interface{}
537+
managedTags := d.Get("tag_names").(*schema.Set)
532538
for _, tagName := range workspace.TagNames {
533-
tagNames = append(tagNames, tagName)
539+
if managedTags.Contains(tagName) || !d.Get("ignore_additional_tag_names").(bool) {
540+
tagNames = append(tagNames, tagName)
541+
}
534542
}
535543
d.Set("tag_names", tagNames)
536544

internal/provider/resource_tfe_workspace_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,10 @@ func TestAccTFEWorkspace_patternsAndPrefixesConflicting(t *testing.T) {
12261226
func TestAccTFEWorkspace_changeTags(t *testing.T) {
12271227
workspace := &tfe.Workspace{}
12281228
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
1229+
tfeClient, err := getClientUsingEnv()
1230+
if err != nil {
1231+
t.Fatal(err)
1232+
}
12291233

12301234
resource.Test(t, resource.TestCase{
12311235
PreCheck: func() { testAccPreCheck(t) },
@@ -1339,6 +1343,44 @@ func TestAccTFEWorkspace_changeTags(t *testing.T) {
13391343
Config: testAccTFEWorkspace_basicBadTag(rInt),
13401344
ExpectError: regexp.MustCompile(`"-Hello" is not a valid tag name.`),
13411345
},
1346+
{
1347+
Config: testAccTFEWorkspace_ignoreAdditional(rInt),
1348+
},
1349+
{
1350+
PreConfig: func() {
1351+
newTags := tfe.WorkspaceAddTagsOptions{Tags: []*tfe.Tag{{Name: "unmanaged"}}}
1352+
err := tfeClient.Workspaces.AddTags(context.Background(), workspace.ID, newTags)
1353+
if err != nil {
1354+
t.Fatal(err)
1355+
}
1356+
},
1357+
Config: testAccTFEWorkspace_ignoreAdditional(rInt),
1358+
Check: resource.ComposeTestCheckFunc(
1359+
testAccCheckTFEWorkspaceExists(
1360+
"tfe_workspace.foobar", workspace, testAccProvider),
1361+
resource.TestCheckResourceAttr(
1362+
"tfe_workspace.foobar", "tag_names.#", "2"),
1363+
resource.TestCheckTypeSetElemAttr(
1364+
"tfe_workspace.foobar", "tag_names.*", "foo"),
1365+
resource.TestCheckTypeSetElemAttr(
1366+
"tfe_workspace.foobar", "tag_names.*", "bar"),
1367+
func(state *terraform.State) error {
1368+
r, err := tfeClient.Workspaces.ListTags(context.Background(), workspace.ID, &tfe.WorkspaceTagListOptions{})
1369+
if err != nil {
1370+
return err
1371+
}
1372+
if len(r.Items) != 3 {
1373+
return fmt.Errorf("expected 3 tags, got %d", len(r.Items))
1374+
}
1375+
for _, tag := range r.Items {
1376+
if tag.Name == "unmanaged" {
1377+
return nil
1378+
}
1379+
}
1380+
return fmt.Errorf("unmanaged tag not found on workspace")
1381+
},
1382+
),
1383+
},
13421384
},
13431385
})
13441386
}
@@ -2781,6 +2823,21 @@ resource "tfe_workspace" "foobar" {
27812823
}`, rInt)
27822824
}
27832825

2826+
func testAccTFEWorkspace_ignoreAdditional(rInt int) string {
2827+
return fmt.Sprintf(`
2828+
resource "tfe_organization" "foobar" {
2829+
name = "tst-terraform-%d"
2830+
2831+
}
2832+
resource "tfe_workspace" "foobar" {
2833+
name = "workspace-test"
2834+
organization = tfe_organization.foobar.id
2835+
auto_apply = true
2836+
tag_names = ["foo", "bar"]
2837+
ignore_additional_tag_names = true
2838+
}`, rInt)
2839+
}
2840+
27842841
func testAccTFEWorkspace_basicBadTag(rInt int) string {
27852842
return fmt.Sprintf(`
27862843
resource "tfe_organization" "foobar" {

website/docs/r/workspace.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ The following arguments are supported:
113113
workspace will display their output as text logs.
114114
* `ssh_key_id` - (Optional) The ID of an SSH key to assign to the workspace.
115115
* `tag_names` - (Optional) A list of tag names for this workspace. Note that tags must only contain lowercase letters, numbers, colons, or hyphens.
116+
* `ignore_additional_tag_names` - (Optional) Explicitly ignores `tag_names`
117+
_not_ defined by config so they will not be overwritten by the configured
118+
tags. This creates exceptional behavior in terraform with respect
119+
to `tag_names` and is not recommended. This value must be applied before it
120+
will be used.
116121
* `terraform_version` - (Optional) The version of Terraform to use for this
117122
workspace. This can be either an exact version or a
118123
[version constraint](https://developer.hashicorp.com/terraform/language/expressions/version-constraints)

0 commit comments

Comments
 (0)