Skip to content

Commit

Permalink
Merge branch 'main' into juliannatetreault/TF-14029-add-manage-permis…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
emlanctot committed May 9, 2024
2 parents 3ca2436 + 5095c61 commit 6eb08ce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/provider/resource_tfe_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func createOPAPolicyOptions(options *tfe.PolicyCreateOptions, d *schema.Resource
enforceOpts.Mode = tfe.EnforcementMode(tfe.EnforcementLevel(v.(string)))
}

options.Enforce = []*tfe.EnforcementOptions{enforceOpts}
options.Enforce = []*tfe.EnforcementOptions{enforceOpts} //nolint:staticcheck // this is still used by TFE versions older than 202306-1

vQuery, ok := d.GetOk("query")
if !ok {
Expand All @@ -218,7 +218,7 @@ func createSentinelPolicyOptions(options *tfe.PolicyCreateOptions, d *schema.Res
enforceOpts.Mode = tfe.EnforcementMode(tfe.EnforcementLevel(v.(string)))
}

options.Enforce = []*tfe.EnforcementOptions{enforceOpts}
options.Enforce = []*tfe.EnforcementOptions{enforceOpts} //nolint:staticcheck // this is still used by TFE versions older than 202306-1
return options
}

Expand Down Expand Up @@ -254,6 +254,7 @@ func resourceTFEPolicyRead(d *schema.ResourceData, meta interface{}) error {
d.Set("description", policy.Description)
d.Set("kind", policy.Kind)

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if len(policy.Enforce) == 1 {
d.Set("enforce_mode", string(policy.Enforce[0].Mode))
}
Expand Down Expand Up @@ -287,6 +288,7 @@ func resourceTFEPolicyUpdate(d *schema.ResourceData, meta interface{}) error {
}
}
if d.HasChange("enforce_mode") {
//nolint:staticcheck // this is still used by TFE versions older than 202306-1
options.Enforce = []*tfe.EnforcementOptions{
{
Path: tfe.String(path),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resource_tfe_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func testAccCheckTFEPolicyAttributes(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "hard-mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand All @@ -419,6 +420,7 @@ func testAccCheckTFEOPAPolicyAttributes(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand All @@ -438,10 +440,12 @@ func testAccCheckTFEDefaultPolicyAttributes(policy *tfe.Policy) resource.TestChe
}

switch policy.Kind {
//nolint:staticcheck // this is still used by TFE versions older than 202306-1
case tfe.Sentinel:
if policy.Enforce[0].Mode != "soft-mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
//nolint:staticcheck // this is still used by TFE versions older than 202306-1
case tfe.OPA:
if policy.Enforce[0].Mode != "advisory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
Expand All @@ -458,6 +462,7 @@ func testAccCheckTFEPolicyAttributesUpdated(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "soft-mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand All @@ -473,6 +478,7 @@ func testAccCheckTFEOPAPolicyAttributesUpdatedQuery(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand All @@ -492,6 +498,7 @@ func testAccCheckTFEOPAPolicyAttributesUpdatedAll(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "advisory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_tfe_sentinel_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func resourceTFESentinelPolicyRead(d *schema.ResourceData, meta interface{}) err
d.Set("name", policy.Name)
d.Set("description", policy.Description)

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if len(policy.Enforce) == 1 {
d.Set("enforce_mode", string(policy.Enforce[0].Mode))
}
Expand All @@ -161,6 +162,7 @@ func resourceTFESentinelPolicyUpdate(d *schema.ResourceData, meta interface{}) e
}

if d.HasChange("enforce_mode") {
//nolint:staticcheck // this is still used by TFE versions older than 202306-1
options.Enforce = []*tfe.EnforcementOptions{
{
Path: tfe.String(d.Get("name").(string) + ".sentinel"),
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_tfe_sentinel_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func testAccCheckTFESentinelPolicyAttributes(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "hard-mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand All @@ -162,6 +163,7 @@ func testAccCheckTFESentinelPolicyAttributesUpdated(
return fmt.Errorf("Bad name: %s", policy.Name)
}

//nolint:staticcheck // this is still used by TFE versions older than 202306-1
if policy.Enforce[0].Mode != "soft-mandatory" {
return fmt.Errorf("Bad enforce mode: %s", policy.Enforce[0].Mode)
}
Expand Down

0 comments on commit 6eb08ce

Please sign in to comment.