Skip to content
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: support 'Enable Remote Apply' flag on environment settings #763

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

TomerHeber
Copy link
Collaborator

Issue & Steps to Reproduce / Feature Request

resolves #761

Solution

  1. Added the schema and implemented the requirements.
  2. Added additional acceptance tests.

@@ -118,6 +118,7 @@ type Environment struct {
BlueprintId string `json:"blueprintId" tfschema:"-"`
IsRemoteBackend *bool `json:"isRemoteBackend" tfschema:"-"`
IsArchived *bool `json:"isArchived" tfschema:"-"`
IsRemoteApplyEnabled bool `json:"isRemoteApplyEnabled"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in golang, this defaults to false.
I don't need it to be a pointer because the schema defaults to 'false'.
(unfortunately, defaults were not used in the early days of the provider which caused a lot of challenges).

Type: schema.TypeBool,
Description: "enables remote apply when set to true (defaults to false). Can only be enabled when is_remote_backend and approve_plan_automatically are enabled. Can only enabled for an existing environment",
Optional: true,
Default: false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important...

@@ -519,6 +525,11 @@ func validateTemplateProjectAssignment(d *schema.ResourceData, apiClient client.
func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
apiClient := meta.(client.ApiClientInterface)

isRemoteApplyEnabled := d.Get("is_remote_apply_enabled").(bool)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_remote_apply_enabled cannot be set to true during environment creation.

isRemoteApplyEnabled := d.Get("is_remote_apply_enabled").(bool)
isRemotedBackend := d.Get("is_remote_backend").(bool)
approvePlanAutomatically := d.Get("approve_plan_automatically").(bool)
if isRemoteApplyEnabled && (!isRemotedBackend || !approvePlanAutomatically) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_remote_apply_enabled may only be true when the others are true.

testCase := resource.TestCase{
Steps: []resource.TestStep{
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regular creation.

),
},
{
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated and set is_remote_apply_enabled to true.

"name": environment.Name,
"project_id": environment.ProjectId,
"template_id": templateId,
"is_remote_backend": !*environment.IsRemoteBackend,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this false to test the error use-case.

}

runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {
gomock.InOrder(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alot of mocks... it's just how the provider works... /:

@@ -1391,6 +1503,22 @@ func TestUnitEnvironmentResource(t *testing.T) {
}

testValidationFailures := func() {
t.Run("create environment with is_remote_apply_enabled set to 'true'", func(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test error on creation when is_remote_apply_enabled is set to true.

@@ -45,6 +45,7 @@ func resourceCustomRole() *schema.Resource {
"VIEW_PROVIDERS",
"VIEW_ENVIRONMENT",
"ASSIGN_ROLE_ON_ENVIRONMENT",
"EDIT_ALLOW_REMOTE_APPLY",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the new custom role.
the provider doesn't check for rbac. That's a backend feature.

Copy link
Contributor

@tomer-landesman tomer-landesman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me 👍🏼

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Dec 4, 2023
@TomerHeber TomerHeber merged commit 88ff9b4 into main Dec 4, 2023
17 checks passed
@TomerHeber TomerHeber deleted the feat-enable-remote-apply-#761 branch December 4, 2023 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-client feature provider ready to merge PR approved - can be merged once the PR owner is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Enable Remote Apply flag on environment settings
2 participants