-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Ability to choose default setting for Deployment Triggers for new Environments #164
Changes from 2 commits
c070c4c
a03f4a5
485d952
50ae45c
5e1b64d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,48 +243,58 @@ type TeamProjectAssignment struct { | |
} | ||
|
||
type Policy struct { | ||
Id string `json:"id"` | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
UpdatedBy string `json:"updatedBy"` | ||
Id string `json:"id"` | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
UpdatedBy string `json:"updatedBy"` | ||
RunPullRequestPlanDefault bool `json:"runPullRequestPlanDefault"` | ||
ContinuousDeploymentDefault bool `json:"continuousDeploymentDefault"` | ||
} | ||
|
||
type PolicyUpdatePayload struct { | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
Id string `json:"id"` | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
UpdatedBy string `json:"updatedBy"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this is a computed attribute and shouldn't be sent on payload... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
RunPullRequestPlanDefault bool `json:"runPullRequestPlanDefault"` | ||
ContinuousDeploymentDefault bool `json:"continuousDeploymentDefault"` | ||
} | ||
|
||
func (p PolicyUpdatePayload) MarshalJSON() ([]byte, error) { | ||
type serial struct { | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments *int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal *int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
ProjectId string `json:"projectId"` | ||
NumberOfEnvironments *int `json:"numberOfEnvironments"` | ||
NumberOfEnvironmentsTotal *int `json:"numberOfEnvironmentsTotal"` | ||
RequiresApprovalDefault bool `json:"requiresApprovalDefault"` | ||
IncludeCostEstimation bool `json:"includeCostEstimation"` | ||
SkipApplyWhenPlanIsEmpty bool `json:"skipApplyWhenPlanIsEmpty"` | ||
DisableDestroyEnvironments bool `json:"disableDestroyEnvironments"` | ||
SkipRedundantDeployments bool `json:"skipRedundantDeployments"` | ||
RunPullRequestPlanDefault bool `json:"runPullRequestPlanDefault"` | ||
ContinuousDeploymentDefault bool `json:"continuousDeploymentDefault"` | ||
} | ||
|
||
s := serial{ | ||
ProjectId: p.ProjectId, | ||
RequiresApprovalDefault: p.RequiresApprovalDefault, | ||
IncludeCostEstimation: p.IncludeCostEstimation, | ||
SkipApplyWhenPlanIsEmpty: p.SkipApplyWhenPlanIsEmpty, | ||
DisableDestroyEnvironments: p.DisableDestroyEnvironments, | ||
SkipRedundantDeployments: p.SkipRedundantDeployments, | ||
ProjectId: p.ProjectId, | ||
RequiresApprovalDefault: p.RequiresApprovalDefault, | ||
IncludeCostEstimation: p.IncludeCostEstimation, | ||
SkipApplyWhenPlanIsEmpty: p.SkipApplyWhenPlanIsEmpty, | ||
DisableDestroyEnvironments: p.DisableDestroyEnvironments, | ||
SkipRedundantDeployments: p.SkipRedundantDeployments, | ||
RunPullRequestPlanDefault: p.RunPullRequestPlanDefault, | ||
ContinuousDeploymentDefault: p.ContinuousDeploymentDefault, | ||
} | ||
|
||
if p.NumberOfEnvironments != 0 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,14 @@ description: |- | |
|
||
### Read-Only | ||
|
||
- **continuous_deployment_default** (Boolean) Redeploy on every push to the git branch default value | ||
- **disable_destroy_environments** (Boolean) Disallow destroying environment in the project | ||
- **id** (String) id of the policy | ||
- **include_cost_estimation** (Boolean) Enable cost estimation for the project | ||
- **number_of_environments** (Number) Max number of environments a single user can have in this project, 0 indicates no limit | ||
- **number_of_environments_total** (Number) Max number of environments in this project, 0 indicates no limit | ||
- **requires_approval_default** (Boolean) Requires approval default value when creating a new environment in the project | ||
- **run_pull_request_plan_default** (Boolean) Run Terraform Plan on Pull Requests for new environments targeting their branch default value | ||
Comment on lines
+24
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why they not near each other - both of them belong trigger policy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its generated |
||
- **skip_apply_when_plan_is_empty** (Boolean) Skip apply when plan has no changes | ||
- **skip_redundant_deployments** (Boolean) Automatically skip queued deployments when a newer deployment is triggered | ||
- **updated_by** (String) updated by | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,11 +38,13 @@ resource "env0_project_policy" "example" { | |
|
||
### Optional | ||
|
||
- **continuous_deployment_default** (Boolean) Redeploy on every push to the git branch default value | ||
- **disable_destroy_environments** (Boolean) Disallow destroying environment in the project | ||
- **include_cost_estimation** (Boolean) Enable cost estimation for the project | ||
- **number_of_environments** (Number) Max number of environments a single user can have in this project, 0 indicates no limit | ||
- **number_of_environments_total** (Number) Max number of environments in this project, 0 indicates no limit | ||
- **requires_approval_default** (Boolean) Requires approval default value when creating a new environment in the project | ||
- **run_pull_request_plan_default** (Boolean) Run Terraform Plan on Pull Requests for new environments targeting their branch default value | ||
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. write one near to other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its generated |
||
- **skip_apply_when_plan_is_empty** (Boolean) Skip apply when plan has no changes | ||
- **skip_redundant_deployments** (Boolean) Automatically skip queued deployments when a newer deployment is triggered | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,18 @@ func resourcePolicy() *schema.Resource { | |
Description: "updated by", | ||
Computed: true, | ||
}, | ||
"run_pull_request_plan_default": { | ||
Type: schema.TypeBool, | ||
Description: "Run Terraform Plan on Pull Requests for new environments targeting their branch default value", | ||
Optional: true, | ||
Default: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since all other fields here don't have a default value setting, I think we should change it to either make all of them with default values, or none. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
"continuous_deployment_default": { | ||
Type: schema.TypeBool, | ||
Description: "Redeploy on every push to the git branch default value", | ||
Optional: true, | ||
Default: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -108,6 +120,8 @@ func setPolicySchema(d *schema.ResourceData, policy client.Policy) { | |
d.Set("disable_destroy_environments", policy.DisableDestroyEnvironments) | ||
d.Set("skip_redundant_deployments", policy.SkipRedundantDeployments) | ||
d.Set("updated_by", policy.UpdatedBy) | ||
d.Set("run_pull_request_plan_default", policy.RunPullRequestPlanDefault) | ||
d.Set("continuous_deployment_default", policy.ContinuousDeploymentDefault) | ||
} | ||
|
||
func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
|
@@ -166,6 +180,12 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte | |
if skipRedundantDeployments, ok := d.GetOk("skip_redundant_deployments"); ok { | ||
payload.SkipRedundantDeployments = skipRedundantDeployments.(bool) | ||
} | ||
if runPullRequestPlanDefault, ok := d.GetOk("run_pull_request_plan_default"); ok { | ||
payload.RunPullRequestPlanDefault = runPullRequestPlanDefault.(bool) | ||
} | ||
if continuousDeploymentDefault, ok := d.GetOk("continuous_deployment_default"); ok { | ||
payload.ContinuousDeploymentDefault = continuousDeploymentDefault.(bool) | ||
} | ||
|
||
_, err := apiClient.PolicyUpdate(payload) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't send the
id
on the project update payload, theid
is a part of the pathThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
50ae45c