-
Notifications
You must be signed in to change notification settings - Fork 14
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: add auto approve field to sub environment configuration #871
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ea50a0
Feat: add auto approve field to sub environment configuration
TomerHeber d8a9cfc
remove unrelated change
TomerHeber 4b9e641
fix test
TomerHeber 57bd8aa
Merge branch 'main' into feat-add-auto-approve-for-sub-#869
TomerHeber 753e36a
fix approve_plan issue
TomerHeber bd3db67
Merge branch 'main' into feat-add-auto-approve-for-sub-#869
TomerHeber ea26110
Merge branch 'main' into feat-add-auto-approve-for-sub-#869
TomerHeber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,13 @@ import ( | |
) | ||
|
||
type SubEnvironment struct { | ||
Id string | ||
Alias string | ||
Revision string | ||
Workflow string | ||
Workspace string | ||
Configuration client.ConfigurationChanges `tfschema:"-"` | ||
Id string | ||
Alias string | ||
Revision string | ||
Workflow string | ||
Workspace string | ||
Configuration client.ConfigurationChanges `tfschema:"-"` | ||
ApprovePlanAutomatically bool | ||
} | ||
|
||
func getSubEnvironments(d *schema.ResourceData) ([]SubEnvironment, error) { | ||
|
@@ -290,7 +291,7 @@ func resourceEnvironment() *schema.Resource { | |
}, | ||
"sub_environment_configuration": { | ||
Type: schema.TypeList, | ||
Description: "the subenvironments for a workflow enviornment. Template type must be 'workflow'. Must match the configuration as defined in 'env0.workflow.yml'", | ||
Description: "the subenvironments for a workflow environment. Template type must be 'workflow'. Must match the configuration as defined in 'env0.workflow.yml'", | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
|
@@ -320,6 +321,12 @@ func resourceEnvironment() *schema.Resource { | |
Optional: true, | ||
Elem: configurationSchema, | ||
}, | ||
"approve_plan_automatically": { | ||
Type: schema.TypeBool, | ||
Description: "when 'true' (default) plans are approved automatically, otherwise ('false') deployment require manual approval", | ||
Optional: true, | ||
Default: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -399,16 +406,16 @@ func setEnvironmentSchema(ctx context.Context, d *schema.ResourceData, environme | |
var newSubEnvironments []interface{} | ||
|
||
for i, iSubEnvironment := range iSubEnvironments.([]interface{}) { | ||
subEnviornment := iSubEnvironment.(map[string]interface{}) | ||
subEnvironment := iSubEnvironment.(map[string]interface{}) | ||
|
||
alias := d.Get(fmt.Sprintf("sub_environment_configuration.%d.alias", i)).(string) | ||
|
||
workkflowSubEnvironment, ok := environment.LatestDeploymentLog.WorkflowFile.Environments[alias] | ||
if ok { | ||
subEnviornment["id"] = workkflowSubEnvironment.EnvironmentId | ||
subEnvironment["id"] = workkflowSubEnvironment.EnvironmentId | ||
} | ||
|
||
newSubEnvironments = append(newSubEnvironments, subEnviornment) | ||
newSubEnvironments = append(newSubEnvironments, subEnvironment) | ||
} | ||
|
||
d.Set("sub_environment_configuration", newSubEnvironments) | ||
|
@@ -744,6 +751,7 @@ func deploy(d *schema.ResourceData, apiClient client.ApiClientInterface) diag.Di | |
Revision: subEnvironment.Revision, | ||
Workspace: subEnvironment.Workspace, | ||
ConfigurationChanges: configurationChanges, | ||
UserRequiresApproval: !subEnvironment.ApprovePlanAutomatically, | ||
} | ||
} | ||
} | ||
|
@@ -885,6 +893,7 @@ func getCreatePayload(d *schema.ResourceData, apiClient client.ApiClientInterfac | |
Revision: subEnvironment.Revision, | ||
ConfigurationChanges: subEnvironment.Configuration, | ||
Workspace: subEnvironment.Workspace, | ||
UserRequiresApproval: !subEnvironment.ApprovePlanAutomatically, | ||
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. notice the '!' |
||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2353,6 +2353,7 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) { | |
} | ||
|
||
updatedSubEnvironment := subEnvironment | ||
updatedSubEnvironment.ApprovePlanAutomatically = false | ||
updatedSubEnvironment.Configuration = append(updatedSubEnvironment.Configuration, client.ConfigurationVariable{ | ||
Name: "name2", | ||
Value: "value2", | ||
|
@@ -2437,6 +2438,7 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) { | |
Revision: subEnvironment.Revision, | ||
Workspace: updatedSubEnvironment.Workspace, | ||
ConfigurationChanges: updatedSubEnvironment.Configuration, | ||
UserRequiresApproval: true, | ||
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.
|
||
}, | ||
}, | ||
} | ||
|
@@ -2499,6 +2501,7 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) { | |
alias = "%s" | ||
revision = "%s" | ||
workspace = "%s" | ||
approve_plan_automatically = false | ||
configuration { | ||
name = "%s" | ||
value = "%s" | ||
|
@@ -2530,6 +2533,7 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) { | |
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.alias", updatedSubEnvironment.Alias), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.revision", updatedSubEnvironment.Revision), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.workspace", updatedSubEnvironment.Workspace), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.approve_plan_automatically", "false"), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.configuration.0.name", updatedSubEnvironment.Configuration[0].Name), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.configuration.0.value", updatedSubEnvironment.Configuration[0].Value), | ||
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.configuration.1.name", updatedSubEnvironment.Configuration[1].Name), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
notice the '!'
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.
so what will happen when it is not there?
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.
the schema has a default value 'true'.
so it will be 'false'.