-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
@@ -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"` |
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.
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, |
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.
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) |
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.
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) { |
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.
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{}{ |
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.
regular creation.
), | ||
}, | ||
{ | ||
Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ |
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.
updated and set is_remote_apply_enabled
to true
.
"name": environment.Name, | ||
"project_id": environment.ProjectId, | ||
"template_id": templateId, | ||
"is_remote_backend": !*environment.IsRemoteBackend, |
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.
making this false
to test the error use-case.
} | ||
|
||
runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { | ||
gomock.InOrder( |
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.
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) { |
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.
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", |
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.
added the new custom role.
the provider doesn't check for rbac. That's a backend feature.
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.
looks good to me 👍🏼
Issue & Steps to Reproduce / Feature Request
resolves #761
Solution