Skip to content

Commit

Permalink
Fix: Skip Redundant deployments typo (#162)
Browse files Browse the repository at this point in the history
* Fix: Skip Redundant deployments typo

* Added total environments and example

* added example to the docs

* updated readme : Adding example in docs section.
  • Loading branch information
liranfarage89 authored Nov 21, 2021
1 parent be26661 commit 5718ddf
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ go generate ./...
- Docs are generated using github.com/hashicorp/terraform-plugin-docs
- Run `./generate-docs.sh` to generate docs
- Must be run manually before releasing a version
- Please add an example to `examples/<resources or data-sources>/env0_<name>` dir and make sure it is added to the docs.

## Release
To release a version to the [Terraform Public Registry](https://registry.terraform.io/providers/env0/env0/latest?pollNotifications=true) -
Expand Down
8 changes: 4 additions & 4 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ type Policy struct {
IncludeCostEstimation bool `json:"includeCostEstimation"`
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"`
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"`
SkipRedundantDepolyments bool `json:"skipRedundantDeployments"`
SkipRedundantDeployments bool `json:"skipRedundantDeployments"`
UpdatedBy string `json:"updatedBy"`
}

Expand All @@ -263,7 +263,7 @@ type PolicyUpdatePayload struct {
IncludeCostEstimation bool `json:"includeCostEstimation"`
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"`
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"`
SkipRedundantDepolyments bool `json:"skipRedundantDeployments"`
SkipRedundantDeployments bool `json:"skipRedundantDeployments"`
}

func (p PolicyUpdatePayload) MarshalJSON() ([]byte, error) {
Expand All @@ -275,7 +275,7 @@ func (p PolicyUpdatePayload) MarshalJSON() ([]byte, error) {
IncludeCostEstimation bool `json:"includeCostEstimation"`
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"`
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"`
SkipRedundantDepolyments bool `json:"skipRedundantDeployments"`
SkipRedundantDeployments bool `json:"skipRedundantDeployments"`
}

s := serial{
Expand All @@ -284,7 +284,7 @@ func (p PolicyUpdatePayload) MarshalJSON() ([]byte, error) {
IncludeCostEstimation: p.IncludeCostEstimation,
SkipApplyWhenPlanIsEmpty: p.SkipApplyWhenPlanIsEmpty,
DisableDestroyEnvironments: p.DisableDestroyEnvironments,
SkipRedundantDepolyments: p.SkipRedundantDepolyments,
SkipRedundantDeployments: p.SkipRedundantDeployments,
}

if p.NumberOfEnvironments != 0 {
Expand Down
19 changes: 18 additions & 1 deletion docs/resources/project_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ description: |-




## Example Usage

```terraform
data "env0_project" "default_project" {
name = "Default Organization Project"
}
resource "env0_project_policy" "example" {
project_id = data.env0_project.default_project.id
number_of_environments = 1
number_of_environments_total = 1
requires_approval_default = true
include_cost_estimation = true
skip_apply_when_plan_is_empty = true
disable_destroy_environments = true
skip_redundant_deployments = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
6 changes: 3 additions & 3 deletions env0/resource_project_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func setPolicySchema(d *schema.ResourceData, policy client.Policy) {
d.Set("include_cost_estimation", policy.IncludeCostEstimation)
d.Set("skip_apply_when_plan_is_empty", policy.SkipApplyWhenPlanIsEmpty)
d.Set("disable_destroy_environments", policy.DisableDestroyEnvironments)
d.Set("skip_redundant_deployments", policy.SkipRedundantDepolyments)
d.Set("skip_redundant_deployments", policy.SkipRedundantDeployments)
d.Set("updated_by", policy.UpdatedBy)
}

Expand Down Expand Up @@ -162,8 +162,8 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte
if disableDestroyEnvironments, ok := d.GetOk("disable_destroy_environments"); ok {
payload.DisableDestroyEnvironments = disableDestroyEnvironments.(bool)
}
if skipRedundantDeployments, ok := d.GetOk("skip_redundant_depolyments"); ok {
payload.SkipRedundantDepolyments = skipRedundantDeployments.(bool)
if skipRedundantDeployments, ok := d.GetOk("skip_redundant_deployments"); ok {
payload.SkipRedundantDeployments = skipRedundantDeployments.(bool)
}

_, err := apiClient.PolicyUpdate(payload)
Expand Down
50 changes: 25 additions & 25 deletions env0/resource_project_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ func TestUnitPolicyResource(t *testing.T) {
accessor := resourceAccessor(resourceType, resourceName)

policy := client.Policy{
Id: "id0",
ProjectId: "project0",
NumberOfEnvironments: 1,
// NumberOfEnvironmentsTotal: 0,
Id: "id0",
ProjectId: "project0",
NumberOfEnvironments: 1,
NumberOfEnvironmentsTotal: 1,
RequiresApprovalDefault: true,
IncludeCostEstimation: false,
SkipApplyWhenPlanIsEmpty: false,
DisableDestroyEnvironments: false,
SkipRedundantDepolyments: false,
IncludeCostEstimation: true,
SkipApplyWhenPlanIsEmpty: true,
DisableDestroyEnvironments: true,
SkipRedundantDeployments: true,
UpdatedBy: "updater0",
}

updatedPolicy := client.Policy{
Id: policy.Id,
ProjectId: policy.ProjectId,
// NumberOfEnvironments: 0,
Id: policy.Id,
ProjectId: policy.ProjectId,
NumberOfEnvironments: 1,
NumberOfEnvironmentsTotal: 1,
RequiresApprovalDefault: false,
IncludeCostEstimation: false,
SkipApplyWhenPlanIsEmpty: false,
DisableDestroyEnvironments: false,
SkipRedundantDepolyments: false,
SkipRedundantDeployments: false,
UpdatedBy: "updater0",
}

Expand All @@ -50,14 +50,14 @@ func TestUnitPolicyResource(t *testing.T) {
Steps: []resource.TestStep{
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
"project_id": policy.ProjectId,
"number_of_environments": policy.NumberOfEnvironments,
// "number_of_environments_total": policy.NumberOfEnvironmentsTotal,
"project_id": policy.ProjectId,
"number_of_environments": policy.NumberOfEnvironments,
"number_of_environments_total": policy.NumberOfEnvironmentsTotal,
"requires_approval_default": policy.RequiresApprovalDefault,
"include_cost_estimation": policy.IncludeCostEstimation,
"skip_apply_when_plan_is_empty": policy.SkipApplyWhenPlanIsEmpty,
"disable_destroy_environments": policy.DisableDestroyEnvironments,
"skip_redundant_deployments": policy.SkipRedundantDepolyments,
"skip_redundant_deployments": policy.SkipRedundantDeployments,
}),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "project_id", policy.ProjectId),
Expand All @@ -67,29 +67,29 @@ func TestUnitPolicyResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "include_cost_estimation", strconv.FormatBool(policy.IncludeCostEstimation)),
resource.TestCheckResourceAttr(accessor, "skip_apply_when_plan_is_empty", strconv.FormatBool(policy.SkipApplyWhenPlanIsEmpty)),
resource.TestCheckResourceAttr(accessor, "disable_destroy_environments", strconv.FormatBool(policy.DisableDestroyEnvironments)),
resource.TestCheckResourceAttr(accessor, "skip_redundant_deployments", strconv.FormatBool(policy.SkipRedundantDepolyments)),
resource.TestCheckResourceAttr(accessor, "skip_redundant_deployments", strconv.FormatBool(policy.SkipRedundantDeployments)),
),
},
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
"project_id": updatedPolicy.ProjectId,
// "number_of_environments": updatedPolicy.NumberOfEnvironments,
"project_id": updatedPolicy.ProjectId,
"number_of_environments": updatedPolicy.NumberOfEnvironments,
"number_of_environments_total": updatedPolicy.NumberOfEnvironmentsTotal,
"requires_approval_default": updatedPolicy.RequiresApprovalDefault,
"include_cost_estimation": updatedPolicy.IncludeCostEstimation,
"skip_apply_when_plan_is_empty": updatedPolicy.SkipApplyWhenPlanIsEmpty,
"disable_destroy_environments": updatedPolicy.DisableDestroyEnvironments,
"skip_redundant_deployments": updatedPolicy.SkipRedundantDepolyments,
"skip_redundant_deployments": updatedPolicy.SkipRedundantDeployments,
}),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(accessor, "project_id", updatedPolicy.ProjectId),
// resource.TestCheckResourceAttr(accessor, "number_of_environments", strconv.Itoa(updatedPolicy.NumberOfEnvironments)),
resource.TestCheckResourceAttr(accessor, "number_of_environments", strconv.Itoa(updatedPolicy.NumberOfEnvironments)),
resource.TestCheckResourceAttr(accessor, "number_of_environments_total", strconv.Itoa(updatedPolicy.NumberOfEnvironmentsTotal)),
resource.TestCheckResourceAttr(accessor, "requires_approval_default", strconv.FormatBool(updatedPolicy.RequiresApprovalDefault)),
resource.TestCheckResourceAttr(accessor, "include_cost_estimation", strconv.FormatBool(updatedPolicy.IncludeCostEstimation)),
resource.TestCheckResourceAttr(accessor, "skip_apply_when_plan_is_empty", strconv.FormatBool(updatedPolicy.SkipApplyWhenPlanIsEmpty)),
resource.TestCheckResourceAttr(accessor, "disable_destroy_environments", strconv.FormatBool(updatedPolicy.DisableDestroyEnvironments)),
resource.TestCheckResourceAttr(accessor, "skip_redundant_deployments", strconv.FormatBool(updatedPolicy.SkipRedundantDepolyments)),
resource.TestCheckResourceAttr(accessor, "skip_redundant_deployments", strconv.FormatBool(updatedPolicy.SkipRedundantDeployments)),
),
},
},
Expand All @@ -105,7 +105,7 @@ func TestUnitPolicyResource(t *testing.T) {
IncludeCostEstimation: policy.IncludeCostEstimation,
SkipApplyWhenPlanIsEmpty: policy.SkipApplyWhenPlanIsEmpty,
DisableDestroyEnvironments: policy.DisableDestroyEnvironments,
SkipRedundantDepolyments: policy.SkipRedundantDepolyments,
SkipRedundantDeployments: policy.SkipRedundantDeployments,
}).Times(1).Return(policy, nil)

// Update
Expand All @@ -117,7 +117,7 @@ func TestUnitPolicyResource(t *testing.T) {
IncludeCostEstimation: updatedPolicy.IncludeCostEstimation,
SkipApplyWhenPlanIsEmpty: updatedPolicy.SkipApplyWhenPlanIsEmpty,
DisableDestroyEnvironments: updatedPolicy.DisableDestroyEnvironments,
SkipRedundantDepolyments: updatedPolicy.SkipRedundantDepolyments,
SkipRedundantDeployments: updatedPolicy.SkipRedundantDeployments,
}).Times(1).Return(policy, nil)

gomock.InOrder(
Expand All @@ -134,7 +134,7 @@ func TestUnitPolicyResource(t *testing.T) {
IncludeCostEstimation: resetPolicy.IncludeCostEstimation,
SkipApplyWhenPlanIsEmpty: resetPolicy.SkipApplyWhenPlanIsEmpty,
DisableDestroyEnvironments: resetPolicy.DisableDestroyEnvironments,
SkipRedundantDepolyments: resetPolicy.SkipRedundantDepolyments,
SkipRedundantDeployments: resetPolicy.SkipRedundantDeployments,
}).Times(1).Return(resetPolicy, nil)
})
}
Expand Down
14 changes: 14 additions & 0 deletions examples/resources/env0_project_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
data "env0_project" "default_project" {
name = "Default Organization Project"
}

resource "env0_project_policy" "example" {
project_id = data.env0_project.default_project.id
number_of_environments = 1
number_of_environments_total = 1
requires_approval_default = true
include_cost_estimation = true
skip_apply_when_plan_is_empty = true
disable_destroy_environments = true
skip_redundant_deployments = true
}
4 changes: 3 additions & 1 deletion tests/integration/011_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data "env0_project" "default" {

resource "env0_project_policy" "test_policy" {
project_id = data.env0_project.default.id
number_of_environments = 1
number_of_environments_total = 1
requires_approval_default = true
include_cost_estimation = false
Expand All @@ -15,7 +16,8 @@ resource "env0_project_policy" "test_policy" {
resource "env0_project_policy" "test_policy_2" {
project_id = data.env0_project.default.id
number_of_environments = 1
requires_approval_default = false
number_of_environments_total = 1
requires_approval_default = true
include_cost_estimation = true
skip_apply_when_plan_is_empty = true
disable_destroy_environments = true
Expand Down

0 comments on commit 5718ddf

Please sign in to comment.