Skip to content

Commit

Permalink
Add support for org-wide assessments setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rexredinger committed Sep 15, 2022
1 parent c278480 commit 1d1ade5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions tfe/data_source_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func dataSourceTFEOrganization() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},

"assessments_enforced": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -79,6 +84,7 @@ func dataSourceTFEOrganizationRead(d *schema.ResourceData, meta interface{}) err
d.Set("owners_team_saml_role_id", org.OwnersTeamSAMLRoleID)
d.Set("two_factor_conformant", org.TwoFactorConformant)
d.Set("send_passing_statuses_for_untriggered_speculative_plans", org.SendPassingStatusesForUntriggeredSpeculativePlans)
d.Set("assessments_enforced", org.AssessmentsEnforced)

return nil
}
12 changes: 12 additions & 0 deletions tfe/resource_tfe_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func resourceTFEOrganization() *schema.Resource {
Optional: true,
Computed: true,
},

"assessments_enforced": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -123,6 +129,7 @@ func resourceTFEOrganizationRead(d *schema.ResourceData, meta interface{}) error
d.Set("owners_team_saml_role_id", org.OwnersTeamSAMLRoleID)
d.Set("cost_estimation_enabled", org.CostEstimationEnabled)
d.Set("send_passing_statuses_for_untriggered_speculative_plans", org.SendPassingStatusesForUntriggeredSpeculativePlans)
d.Set("assessments_enforced", org.AssessmentsEnforced)

return nil
}
Expand Down Expand Up @@ -166,6 +173,11 @@ func resourceTFEOrganizationUpdate(d *schema.ResourceData, meta interface{}) err
options.SendPassingStatusesForUntriggeredSpeculativePlans = tfe.Bool(sendPassingStatusesForUntriggeredSpeculativePlans.(bool))
}

// If cost_estimation_enabled is supplied, set it using the options struct.
if assessmentsEnforced, ok := d.GetOkExists("assessments_enforced"); ok {
options.assessmentsEnforced = tfe.Bool(assessmentsEnforced.(bool))
}

log.Printf("[DEBUG] Update configuration of organization: %s", d.Id())
org, err := tfeClient.Organizations.Update(ctx, d.Id(), options)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions tfe/resource_tfe_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func TestAccTFEOrganization_full(t *testing.T) {
"tfe_organization.foobar", "cost_estimation_enabled", "false"),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "send_passing_statuses_for_untriggered_speculative_plans", "false"),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "assessments_enforced", "false"),
),
},
},
Expand All @@ -91,9 +93,11 @@ func TestAccTFEOrganization_update_costEstimation(t *testing.T) {

// First update
costEstimationEnabled1 := true
assessmentsEnforced1 := true

// Second update
costEstimationEnabled2 := false
assessmentsEnforced2 := false
updatedName := org.Name + "_foobar"

resource.Test(t, resource.TestCase{
Expand All @@ -102,7 +106,7 @@ func TestAccTFEOrganization_update_costEstimation(t *testing.T) {
CheckDestroy: testAccCheckTFEOrganizationDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEOrganization_update(org.Name, org.Email, costEstimationEnabled1),
Config: testAccTFEOrganization_update(org.Name, org.Email, costEstimationEnabled1, assessmentsEnforced1),
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEOrganizationExists(
"tfe_organization.foobar", org),
Expand All @@ -123,11 +127,13 @@ func TestAccTFEOrganization_update_costEstimation(t *testing.T) {
"tfe_organization.foobar", "cost_estimation_enabled", strconv.FormatBool(costEstimationEnabled1)),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "send_passing_statuses_for_untriggered_speculative_plans", "false"),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "assessments_enforced", strconv.FormatBool(assessmentsEnforced1)),
),
},

{
Config: testAccTFEOrganization_update(updatedName, org.Email, costEstimationEnabled2),
Config: testAccTFEOrganization_update(updatedName, org.Email, costEstimationEnabled2, assessmentsEnforced2),
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEOrganizationExists(
"tfe_organization.foobar", org),
Expand All @@ -146,6 +152,8 @@ func TestAccTFEOrganization_update_costEstimation(t *testing.T) {
"tfe_organization.foobar", "owners_team_saml_role_id", "owners"),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "cost_estimation_enabled", strconv.FormatBool(costEstimationEnabled2)),
resource.TestCheckResourceAttr(
"tfe_organization.foobar", "assessments_enforced", strconv.FormatBool(assessmentsEnforced2)),
),
},
},
Expand Down Expand Up @@ -370,10 +378,11 @@ resource "tfe_organization" "foobar" {
collaborator_auth_policy = "password"
owners_team_saml_role_id = "owners"
cost_estimation_enabled = false
assessments_enforced = false
}`, rInt)
}

func testAccTFEOrganization_update(orgName string, orgEmail string, costEstimationEnabled bool) string {
func testAccTFEOrganization_update(orgName string, orgEmail string, costEstimationEnabled bool, assessmentsEnforced bool) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "%s"
Expand All @@ -382,5 +391,6 @@ resource "tfe_organization" "foobar" {
session_remember_minutes = 3600
owners_team_saml_role_id = "owners"
cost_estimation_enabled = %t
}`, orgName, orgEmail, costEstimationEnabled)
assessments_enforced = %t
}`, orgName, orgEmail, costEstimationEnabled, assessmentsEnforced)
}

0 comments on commit 1d1ade5

Please sign in to comment.