Skip to content

Commit

Permalink
Merge pull request #1149 from hashicorp/nf/nov23-name-optional-test
Browse files Browse the repository at this point in the history
[d/tfe_organization] Make name argument optional if configured for the provider [COMBINED]
  • Loading branch information
nfagerlund authored Nov 21, 2023
2 parents ce83189 + 706dee8 commit c0ef1bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
FEATURES:
* `d/tfe_registry_module`: Add `vcs_repo.tags` and `vcs_repo.branch` attributes to allow configuration of `publishing_mechanism`. Add `test_config` to support running tests on `branch`-based registry modules, by @hashimoon [1096](https://github.com/hashicorp/terraform-provider-tfe/pull/1096)

ENHANCEMENTS:
* `d/tfe_organization`: Make `name` argument optional if configured for the provider, by @tmatilai [1133](https://github.com/hashicorp/terraform-provider-tfe/pull/1133)

## v0.50.0

FEATURES:
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/data_source_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func dataSourceTFEOrganization() *schema.Resource {
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"external_id": {
Expand Down Expand Up @@ -88,6 +88,7 @@ func dataSourceTFEOrganizationRead(d *schema.ResourceData, meta interface{}) err

log.Printf("[DEBUG] Setting Organization Attributes")
d.SetId(org.ExternalID)
d.Set("name", org.Name)
d.Set("external_id", org.ExternalID)
d.Set("collaborator_auth_policy", org.CollaboratorAuthPolicy)
d.Set("cost_estimation_enabled", org.CostEstimationEnabled)
Expand Down
28 changes: 28 additions & 0 deletions internal/provider/data_source_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package provider
import (
"fmt"
"math/rand"
"regexp"
"testing"
"time"

Expand Down Expand Up @@ -63,6 +64,27 @@ func TestAccTFEOrganizationDataSource_defaultProject(t *testing.T) {
})
}

// The data source will use the default org name from provider config if omitted.
func TestAccTFEOrganizationDataSource_defaultOrganization(t *testing.T) {
defaultOrgName, _ := setupDefaultOrganization(t)
providers := providerWithDefaultOrganization(defaultOrgName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: testAccTFEOrganizationDataSourceConfig_noName(),
Check: resource.ComposeAggregateTestCheckFunc(
// check data attrs
resource.TestCheckResourceAttr("data.tfe_organization.foo", "name", defaultOrgName),
resource.TestMatchResourceAttr("data.tfe_organization.foo", "email", regexp.MustCompile(`@tfe\.local\z`)),
),
},
},
})
}

func testAccTFEOrganizationDataSourceConfig_basic(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foo" {
Expand All @@ -75,3 +97,9 @@ data "tfe_organization" "foo" {
depends_on = [tfe_organization.foo]
}`, rInt)
}

func testAccTFEOrganizationDataSourceConfig_noName() string {
return `
data "tfe_organization" "foo" {
}`
}
3 changes: 1 addition & 2 deletions website/docs/d/organization.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ data "tfe_organization" "foo" {
## Argument Reference

The following arguments are supported:
* `name` - (Required) Name of the organization.
* `name` - (Optional) Name of the organization. If omitted, organization must be defined in the provider config.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `name` - Name of the organization.
* `email` - Admin email address.
* `external_id` - An identifier for the organization.
* `assessments_enforced` - (Available only in Terraform Cloud) Whether to force health assessments (drift detection) on all eligible workspaces or allow workspaces to set thier own preferences.
Expand Down

0 comments on commit c0ef1bf

Please sign in to comment.