Skip to content

Commit

Permalink
Feat: add env0_project_policy option for Environment Output
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Jul 15, 2024
1 parent 6d11c30 commit aa14aca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/project_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Policy struct {
ForceRemoteBackend bool `json:"forceRemoteBackend"`
DriftDetectionCron string `json:"driftDetectionCron"`
DriftDetectionEnabled bool `json:"driftDetectionEnabled"`
OutputsAsInputsEnabled bool `json:"outputsAsInputsEnabled"`
}

type PolicyUpdatePayload struct {
Expand All @@ -38,6 +39,7 @@ type PolicyUpdatePayload struct {
DriftDetectionCron string `json:"driftDetectionCron"`
DriftDetectionEnabled bool `json:"driftDetectionEnabled"`
VcsPrCommentsEnabledDefault bool `json:"vcsPrCommentsEnabledDefault"`
OutputsAsInputsEnabled bool `json:"outputsAsInputsEnabled"`
}

// Policy retrieves a policy from the API
Expand Down
7 changes: 0 additions & 7 deletions env0/resource_configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,6 @@ resource "%s" "test" {
createParams := configurationVariableCreateParams
createParams.IsReadOnly = true
createParams.IsRequired = true
updateParams := createParams
updateParams.Name = newConfigVar.Name
updateParams.Value = ""
updateParams.Description = newConfigVar.Description
updateParams.Format = client.HCL
updateParams.IsReadOnly = *newConfigVar.IsReadOnly
updateParams.IsRequired = *newConfigVar.IsRequired

mock.EXPECT().ConfigurationVariableCreate(createParams).Times(1).Return(newConfigVar, nil)
gomock.InOrder(
Expand Down
8 changes: 7 additions & 1 deletion env0/resource_project_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ func resourceProjectPolicy() *schema.Resource {
},
"vcs_pr_comments_enabled_default": {
Type: schema.TypeBool,
Description: "if 'true' all environments created in this project will be created with an 'enabled' running VCS PR plan/apply commands using PR comments",
Description: "if 'true' all environments created in this project will be created with an 'enabled' running VCS PR plan/apply commands using PR comments. Default is 'false'",
Optional: true,
Default: false,
},
"outputs_as_inputs_enabled": {
Type: schema.TypeBool,
Description: "if 'true' enables 'environment outputs'. Default is 'false'",
Optional: true,
Default: false,
},
Expand Down
5 changes: 5 additions & 0 deletions env0/resource_project_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestUnitProjectPolicyResource(t *testing.T) {
DriftDetectionCron: "0 4 * * *",
DriftDetectionEnabled: true,
VcsPrCommentsEnabledDefault: true,
OutputsAsInputsEnabled: true,
}

updatedPolicy := client.Policy{
Expand Down Expand Up @@ -72,6 +73,7 @@ func TestUnitProjectPolicyResource(t *testing.T) {
"force_remote_backend": policy.ForceRemoteBackend,
"drift_detection_cron": policy.DriftDetectionCron,
"vcs_pr_comments_enabled_default": policy.VcsPrCommentsEnabledDefault,
"outputs_as_inputs_enabled": policy.OutputsAsInputsEnabled,
}),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "project_id", policy.ProjectId),
Expand All @@ -89,6 +91,7 @@ func TestUnitProjectPolicyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "force_remote_backend", strconv.FormatBool(policy.ForceRemoteBackend)),
resource.TestCheckResourceAttr(accessor, "drift_detection_cron", policy.DriftDetectionCron),
resource.TestCheckResourceAttr(accessor, "vcs_pr_comments_enabled_default", strconv.FormatBool(policy.VcsPrCommentsEnabledDefault)),
resource.TestCheckResourceAttr(accessor, "outputs_as_inputs_enabled", strconv.FormatBool(policy.OutputsAsInputsEnabled)),
),
},
{
Expand Down Expand Up @@ -116,6 +119,7 @@ func TestUnitProjectPolicyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "force_remote_backend", strconv.FormatBool(updatedPolicy.ForceRemoteBackend)),
resource.TestCheckResourceAttr(accessor, "drift_detection_cron", updatedPolicy.DriftDetectionCron),
resource.TestCheckResourceAttr(accessor, "vcs_pr_comments_enabled_default", strconv.FormatBool(updatedPolicy.VcsPrCommentsEnabledDefault)),
resource.TestCheckResourceAttr(accessor, "outputs_as_inputs_enabled", strconv.FormatBool(updatedPolicy.OutputsAsInputsEnabled)),
),
},
},
Expand All @@ -139,6 +143,7 @@ func TestUnitProjectPolicyResource(t *testing.T) {
DriftDetectionEnabled: true,
DriftDetectionCron: policy.DriftDetectionCron,
VcsPrCommentsEnabledDefault: policy.VcsPrCommentsEnabledDefault,
OutputsAsInputsEnabled: policy.OutputsAsInputsEnabled,
}).Times(1).Return(policy, nil),
mock.EXPECT().Policy(gomock.Any()).Times(2).Return(policy, nil), // 1 after create, 1 before update
// Update
Expand Down
1 change: 1 addition & 0 deletions tests/integration/011_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "env0_project_policy" "test_policy_2" {
disable_destroy_environments = true
skip_redundant_deployments = true
vcs_pr_comments_enabled_default = true
outputs_as_inputs_enabled = true
}

resource "env0_project_policy" "test_policy_ttl" {
Expand Down

0 comments on commit aa14aca

Please sign in to comment.