Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
1natedawg authored Aug 5, 2024
2 parents 2a9e052 + f88988b commit 9b9580d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: jrm ./ci-summary-provider.xml "junit-test-summary-0/*.xml" "junit-test-summary-1/*.xml" "junit-test-summary-2/*.xml" "junit-test-summary-3/*.xml" "junit-test-summary-4/*.xml"

- name: Upload test artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: junit-test-summary
path: ./ci-summary-provider.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
go build -o terraform-provider-tfe
- name: Upload test artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: terraform-provider-tfe
path: terraform-provider-tfe
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fetch-depth: 0
- name: Generate Release Notes
run: sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $(git describe --abbrev=0 --exclude="$(git describe --abbrev=0 --match='v*.*.*' --tags)" --match='v*.*.*' --tags | tr -d v)/q;p" CHANGELOG.md > release-notes.txt
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
- uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: release-notes
path: release-notes.txt
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## Unreleased

ENHANCEMENTS:
* `d/tfe_project`: Add `workspace_names` attribute, by @1natedawg [#1429](https://github.com/hashicorp/terraform-provider-tfe/pull/1429)

BUG FIXES:
* `r/tfe_workspace` html_url is now planned to be recomputed when `name` changes. Previously, changed values would show up on the next plan, by @brandonc [1422](https://github.com/hashicorp/terraform-provider-tfe/issues/1422)

## v0.57.1

* `r/tfe_stack` initial support for this BETA feature was released in v0.57.0 but the documentation link was broken and it was not mentioned in the release notes. NOTE: This resource is subject to change and has limited support in HCP Terraform.
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestConfigureEnvOrganization(t *testing.T) {
// The TFE Provider tests use these environment variables, which are set in the
// GitHub Action workflow file .github/workflows/ci.yml.
func testAccGithubPreCheck(t *testing.T) {
skipUnlessAfterDate(t, time.Date(2024, 8, 1, 0, 0, 0, 0, time.UTC))
skipUnlessAfterDate(t, time.Date(2024, 9, 1, 0, 0, 0, 0, time.UTC))

if envGithubToken == "" {
t.Skip("Please set GITHUB_TOKEN to run this test")
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_tfe_registry_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ func testAccCheckTFERegistryModuleDestroy(s *terraform.State) error {
}

func testAccPreCheckTFERegistryModule(t *testing.T) {
skipUnlessAfterDate(t, time.Date(2024, 8, 1, 0, 0, 0, 0, time.UTC))
skipUnlessAfterDate(t, time.Date(2024, 9, 1, 0, 0, 0, 0, time.UTC))

if envGithubToken == "" {
t.Skip("Please set GITHUB_TOKEN to run this test")
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func resourceTFEWorkspace() *schema.Resource {
return err
}

if d.HasChange("name") {
if err := d.SetNewComputed("html_url"); err != nil {
return err
}
}

return nil
},

Expand Down
83 changes: 83 additions & 0 deletions internal/provider/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ func TestAccTFEWorkspace_customProject(t *testing.T) {
})
}

func TestAccTFEWorkspace_HTMLURL(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

// When name is changed, the html_url should be updated as well
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFEWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEWorkspace_HTMLURL(rInt),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("tfe_workspace.foobar", "name", "workspace-test"),
resource.TestCheckResourceAttrPair("tfe_workspace.foobar", "html_url", "tfe_project.foobar", "description"),
testAccCheckTFEWorkspaceHTMLURLHasSuffix("tfe_workspace.foobar", "workspace-test"),
),
},
{
Config: testAccTFEWorkspace_HTMLURLRenamed(rInt),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("tfe_workspace.foobar", "name", "workspace-test-renamed"),
resource.TestCheckResourceAttrPair("tfe_workspace.foobar", "html_url", "tfe_project.foobar", "description"),
testAccCheckTFEWorkspaceHTMLURLHasSuffix("tfe_workspace.foobar", "workspace-test-renamed"),
),
},
},
})
}

func TestTagValidation(t *testing.T) {
testCases := []struct {
tag string
Expand Down Expand Up @@ -2249,6 +2278,22 @@ func TestTFEWorkspace_delete_withoutCanForceDeletePermission(t *testing.T) {
}
}

func testAccCheckTFEWorkspaceHTMLURLHasSuffix(resourceName, suffix string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("not found: %s", resourceName)
}

url := rs.Primary.Attributes["html_url"]
if !strings.HasSuffix(url, suffix) {
return fmt.Errorf("expected %q to have suffix %q", url, suffix)
}

return nil
}
}

func testAccCheckTFEWorkspaceExists(
n string, workspace *tfe.Workspace, p *schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -2849,6 +2894,44 @@ resource "tfe_workspace" "foobar" {
}`, rInt, aart)
}

func testAccTFEWorkspace_HTMLURL(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "tst-terraform-%d"
email = "[email protected]"
}
resource "tfe_project" "foobar" {
name = "testproject"
organization = tfe_organization.foobar.id
description = tfe_workspace.foobar.html_url
}
resource "tfe_workspace" "foobar" {
name = "workspace-test"
organization = tfe_organization.foobar.id
}`, rInt)
}

func testAccTFEWorkspace_HTMLURLRenamed(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "tst-terraform-%d"
email = "[email protected]"
}
resource "tfe_project" "foobar" {
name = "testproject"
organization = tfe_organization.foobar.id
description = tfe_workspace.foobar.html_url
}
resource "tfe_workspace" "foobar" {
name = "workspace-test-renamed"
organization = tfe_organization.foobar.id
}`, rInt)
}

func testAccTFEWorkspace_defaultOrg() string {
return `
resource "tfe_workspace" "foobar" {
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/stack.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
Expand Down

0 comments on commit 9b9580d

Please sign in to comment.