Skip to content

Commit

Permalink
Merge branch 'main' into abdu/branch_based_module_initial_version
Browse files Browse the repository at this point in the history
  • Loading branch information
aaabdelgany committed May 22, 2024
2 parents 1df251d + 036e812 commit 8114daf
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/actions/lint-provider-tfe/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
using: composite
steps:
- name: Setup Go Environment
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: "go.mod"
cache: true
Expand Down
130 changes: 63 additions & 67 deletions .github/actions/test-provider-tfe/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

name: TESTS ARE TEMPOARILY DISABLED
name: Test
description: Tests terraform-provider-tfe within a matrix
inputs:
admin_configuration_token:
Expand Down Expand Up @@ -51,76 +51,72 @@ inputs:
runs:
using: composite
steps:
- name: NO-OP
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: go.mod
cache: true

- name: Sync dependencies
shell: bash
run: |
echo "Tests are skipped. Please test manually."
# - name: Set up Go
# uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
# with:
# go-version-file: go.mod
# cache: true

# - name: Sync dependencies
# shell: bash
# run: |
# go mod download
# go mod tidy
go mod download
go mod tidy
# - name: Install gotestsum
# shell: bash
# run: go install gotest.tools/gotestsum@latest
- name: Install gotestsum
shell: bash
run: go install gotest.tools/gotestsum@latest

# - name: Download artifact
# id: download-artifact
# uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 # v2.27.0
# with:
# workflow_conclusion: success
# name: junit-test-summary
# if_no_artifact_found: warn
# branch: main
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 # v2.27.0
with:
workflow_conclusion: success
name: junit-test-summary
if_no_artifact_found: warn
branch: main

# - name: Split acceptance tests
# id: test_split
# uses: hashicorp-forge/go-test-split-action@796beedbdb3d1bea14cad2d3057bab5c5cf15fe5 # v1.0.2
# with:
# index: ${{ inputs.matrix_index }}
# total: ${{ inputs.matrix_total }}
# junit-summary: ./ci-summary-provider.xml
# # When tests are split and run concurrently, lists_tests arg in ci.yml will skip the TestAccTFESAMLSettings_omnibus test suite
# list: ${{ inputs.list_tests }}
- name: Split acceptance tests
id: test_split
uses: hashicorp-forge/go-test-split-action@796beedbdb3d1bea14cad2d3057bab5c5cf15fe5 # v1.0.2
with:
index: ${{ inputs.matrix_index }}
total: ${{ inputs.matrix_total }}
junit-summary: ./ci-summary-provider.xml
# When tests are split and run concurrently, lists_tests arg in ci.yml will skip the TestAccTFESAMLSettings_omnibus test suite
list: ${{ inputs.list_tests }}

# - name: Run Tests
# shell: bash
# env:
# TFE_HOSTNAME: "${{ inputs.hostname }}"
# TFE_TOKEN: "${{ inputs.token }}"
# TFE_ADMIN_CONFIGURATION_TOKEN: ${{ inputs.admin_configuration_token }}
# TFE_ADMIN_PROVISION_LICENSES_TOKEN: ${{ inputs.admin_provision_licenses_token }}
# TFE_ADMIN_SECURITY_MAINTENANCE_TOKEN: ${{ inputs.admin_security_maintenance_token }}
# TFE_ADMIN_SITE_ADMIN_TOKEN: ${{ inputs.admin_site_admin_token }}
# TFE_ADMIN_SUBSCRIPTION_TOKEN: ${{ inputs.admin_subscription_token }}
# TFE_ADMIN_SUPPORT_TOKEN: ${{ inputs.admin_support_token }}
# TFE_ADMIN_VERSION_MAINTENANCE_TOKEN: ${{ inputs.admin_version_maintenance_token }}
# TFE_USER1: tfe-provider-user1
# TFE_USER2: tfe-provider-user2
# TF_ACC: "1"
# ENABLE_TFE: "${{ inputs.enterprise }}"
# RUN_TASKS_URL: "http://testing-mocks.tfe:22180/runtasks/pass"
# GITHUB_POLICY_SET_IDENTIFIER: "hashicorp/test-policy-set"
# GITHUB_REGISTRY_MODULE_IDENTIFIER: "hashicorp/terraform-random-module"
# GITHUB_WORKSPACE_IDENTIFIER: "hashicorp/terraform-random-module"
# GITHUB_WORKSPACE_BRANCH: "main"
# GITHUB_TOKEN: "${{ inputs.testing-github-token }}"
# MOD_PROVIDER: github.com/hashicorp/terraform-provider-tfe
# MOD_TFE: github.com/hashicorp/terraform-provider-tfe/internal/provider
# MOD_VERSION: github.com/hashicorp/terraform-provider-tfe/version
# run: |
# gotestsum --junitfile summary.xml --format short-verbose -- $MOD_PROVIDER $MOD_TFE $MOD_VERSION -v -timeout=30m -run "${{ steps.test_split.outputs.run }}"
- name: Run Tests
shell: bash
env:
TFE_HOSTNAME: "${{ inputs.hostname }}"
TFE_TOKEN: "${{ inputs.token }}"
TFE_ADMIN_CONFIGURATION_TOKEN: ${{ inputs.admin_configuration_token }}
TFE_ADMIN_PROVISION_LICENSES_TOKEN: ${{ inputs.admin_provision_licenses_token }}
TFE_ADMIN_SECURITY_MAINTENANCE_TOKEN: ${{ inputs.admin_security_maintenance_token }}
TFE_ADMIN_SITE_ADMIN_TOKEN: ${{ inputs.admin_site_admin_token }}
TFE_ADMIN_SUBSCRIPTION_TOKEN: ${{ inputs.admin_subscription_token }}
TFE_ADMIN_SUPPORT_TOKEN: ${{ inputs.admin_support_token }}
TFE_ADMIN_VERSION_MAINTENANCE_TOKEN: ${{ inputs.admin_version_maintenance_token }}
TFE_USER1: tfe-provider-user1
TFE_USER2: tfe-provider-user2
TF_ACC: "1"
ENABLE_TFE: "${{ inputs.enterprise }}"
RUN_TASKS_URL: "http://testing-mocks.tfe:22180/runtasks/pass"
GITHUB_POLICY_SET_IDENTIFIER: "hashicorp/test-policy-set"
GITHUB_REGISTRY_MODULE_IDENTIFIER: "hashicorp/terraform-random-module"
GITHUB_WORKSPACE_IDENTIFIER: "hashicorp/terraform-random-module"
GITHUB_WORKSPACE_BRANCH: "main"
GITHUB_TOKEN: "${{ inputs.testing-github-token }}"
MOD_PROVIDER: github.com/hashicorp/terraform-provider-tfe
MOD_TFE: github.com/hashicorp/terraform-provider-tfe/internal/provider
MOD_VERSION: github.com/hashicorp/terraform-provider-tfe/version
run: |
gotestsum --junitfile summary.xml --format short-verbose -- $MOD_PROVIDER $MOD_TFE $MOD_VERSION -v -timeout=30m -run "${{ steps.test_split.outputs.run }}"
# - name: Upload test artifacts
# uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
# with:
# name: junit-test-summary-${{ matrix.index }}
# path: summary.xml
# retention-days: 1
- name: Upload test artifacts
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: junit-test-summary-${{ matrix.index }}
path: summary.xml
retention-days: 1
13 changes: 3 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ concurrency:
cancel-in-progress: true

jobs:
notice:
name: TESTS ARE TEMPORARILY DISABLED- RUN CHANGED RESOURCE TESTS LOCALLY
runs-on: ubuntu-latest
steps:
- name: NO-OP
run: |
echo "Tests are skipped. Please test manually."
lint:
name: lint
runs-on: ubuntu-latest
Expand All @@ -31,8 +24,8 @@ jobs:
fail-fast: false
matrix:
# If you adjust these parameters, also adjust the jrm input files on the "Merge reports" step below
total: [ 1 ]
index: [ 0 ]
total: [ 5 ]
index: [ 0, 1, 2, 3, 4 ]
steps:
- name: Fetch Outputs
id: tflocal
Expand Down Expand Up @@ -80,7 +73,7 @@ jobs:
run: npm install -g junit-report-merger

- name: Merge reports
run: jrm ./ci-summary-provider.xml "junit-test-summary-0/*.xml"
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
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 @@ -35,7 +35,7 @@ jobs:
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: go.mod
cache: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nightly-tfe-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
strategy:
fail-fast: false
matrix:
total: [ 1 ]
index: [ 0 ]
total: [ 5 ]
index: [ 0, 1, 2, 3, 4 ]
steps:
- name: Fetch Outputs
id: tflocal
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: go.mod
check-latest: true
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ENHANCEMENTS:
* `r/tfe_oauth_client`: Add Bitbucket Data Center support with the `bitbucket_data_center` option for `service_provider` by @zainq11 [#1303](https://github.com/hashicorp/terraform-provider-tfe/pull/1304)
* `r/tfe_workspace`: Add an `auto_destroy_at` attribute for scheduling an auto-destroy run in the future, by @notchairmk [1354](https://github.com/hashicorp/terraform-provider-tfe/pull/1354)
* `d/tfe_workspace`: Add an `auto_destroy_at` attribute for reading a scheduled auto-destroy, by @notchairmk [1354](https://github.com/hashicorp/terraform-provider-tfe/pull/1354)
* `r/tfe_registry_module`: Add `initial_version` support for Branch Based Modules by @aaabdelgany [#1363](https://github.com/hashicorp/terraform-provider-tfe/pull/1363)

## v0.55.0
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/data_source_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func dataSourceTFEWorkspace() *schema.Resource {
Computed: true,
},

"auto_destroy_at": {
Type: schema.TypeString,
Computed: true,
},

"file_triggers_enabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -240,6 +245,12 @@ func dataSourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error
d.Set("operations", workspace.Operations)
d.Set("policy_check_failures", workspace.PolicyCheckFailures)

autoDestroyAt, err := flattenAutoDestroyAt(workspace.AutoDestroyAt)
if err != nil {
return fmt.Errorf("Error flattening auto destroy during read: %w", err)
}
d.Set("auto_destroy_at", autoDestroyAt)

// If target tfe instance predates projects, then workspace.Project will be nil
if workspace.Project != nil {
d.Set("project_id", workspace.Project.ID)
Expand Down
57 changes: 57 additions & 0 deletions internal/provider/data_source_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ func TestAccTFEWorkspaceDataSourceWithTriggerPatterns(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccTFEWorkspaceDataSourceConfig_basic(rInt),
Check: resource.TestCheckResourceAttr("data.tfe_workspace.foobar", "auto_destroy_at", ""),
},
{
Config: testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroy(rInt),
Check: resource.TestCheckResourceAttr("data.tfe_workspace.foobar", "auto_destroy_at", "2100-01-01T00:00:00Z"),
},
},
})
}

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

Expand Down Expand Up @@ -243,6 +262,44 @@ data "tfe_workspace" "foobar" {
}`, rInt, rInt, aart)
}

func testAccTFEWorkspaceDataSourceConfig_basic(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "tst-terraform-%d"
email = "admin@company.com"
}
resource "tfe_workspace" "foobar" {
name = "workspace-test-%d"
organization = tfe_organization.foobar.id
description = "provider-testing"
}
data "tfe_workspace" "foobar" {
name = tfe_workspace.foobar.name
organization = tfe_workspace.foobar.organization
}`, rInt, rInt)
}

func testAccTFEWorkspaceDataSourceConfig_basicWithAutoDestroy(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "tst-terraform-%d"
email = "admin@company.com"
}
resource "tfe_workspace" "foobar" {
name = "workspace-test-%d"
organization = tfe_organization.foobar.id
description = "provider-testing"
auto_destroy_at = "2100-01-01T00:00:00Z"
}
data "tfe_workspace" "foobar" {
name = tfe_workspace.foobar.name
organization = tfe_workspace.foobar.organization
}`, rInt, rInt)
}
func testAccTFEWorkspaceDataSourceConfigWithTriggerPatterns(workspaceName string, organizationName string) string {
return fmt.Sprintf(`
data "tfe_workspace" "foobar" {
Expand Down
16 changes: 14 additions & 2 deletions internal/provider/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ func skipUnlessBeta(t *testing.T) {
}
}

// Temporarily skip a test that may be experiencing API errors. This method
// purposefully errors after the set date to remind contributors to remove this check
// and verify that the API errors are no longer occurring.
func skipUnlessAfterDate(t *testing.T, d time.Time) {
today := time.Now()
if today.After(d) {
t.Fatalf("This test was temporarily skipped and has now expired. Remove this check to run this test.")
} else {
t.Skipf("Temporarily skipping test due to external issues: %s", t.Name())
}
}

func enterpriseEnabled() bool {
return os.Getenv("ENABLE_TFE") == "1"
}
Expand Down Expand Up @@ -255,9 +267,9 @@ func randomString(t *testing.T) string {
return v
}

type retryableFn func() (interface{}, error)
type retryableFn func() (any, error)

func retryFn(maxRetries, secondsBetween int, f retryableFn) (interface{}, error) {
func retryFn(maxRetries, secondsBetween int, f retryableFn) (any, error) {
tick := time.NewTicker(time.Duration(secondsBetween) * time.Second)
retries := 0

Expand Down
2 changes: 2 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ 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, 5, 24, 0, 0, 0, 0, time.UTC))

if envGithubToken == "" {
t.Skip("Please set GITHUB_TOKEN to run this test")
}
Expand Down
Loading

0 comments on commit 8114daf

Please sign in to comment.