Skip to content

Commit

Permalink
Fix: disallowing remote state access returns 400 bad request (#714)
Browse files Browse the repository at this point in the history
* Fix: disallowing remote state access returns 400 bad request

* send an empty array

* comment test

* added a comment
  • Loading branch information
TomerHeber committed Sep 21, 2023
1 parent 51748f7 commit 1fa7a0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion client/remote_state_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type RemoteStateAccessConfiguration struct {

type RemoteStateAccessConfigurationCreate struct {
AccessibleFromEntireOrganization bool `json:"accessibleFromEntireOrganization"`
AllowedProjectIds []string `json:"allowedProjectIds,omitempty"`
AllowedProjectIds []string `json:"allowedProjectIds"`
}

func (client *ApiClient) RemoteStateAccessConfiguration(environmentId string) (*RemoteStateAccessConfiguration, error) {
Expand All @@ -22,6 +22,11 @@ func (client *ApiClient) RemoteStateAccessConfiguration(environmentId string) (*
}

func (client *ApiClient) RemoteStateAccessConfigurationCreate(environmentId string, payload RemoteStateAccessConfigurationCreate) (*RemoteStateAccessConfiguration, error) {
// The API doesn't accept "null". If the array isn't set, pass "[]" instead.
if payload.AllowedProjectIds == nil {
payload.AllowedProjectIds = []string{}
}

var result RemoteStateAccessConfiguration
if err := client.http.Put("/remote-backend/states/"+environmentId+"/access-control", payload, &result); err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ resource "env0_team_environment_assignment" "team_role_environment_assignment" {
role_id = var.second_run ? env0_custom_role.custom_role1.id : env0_custom_role.custom_role2.id
}

/* TODO: need to add an integration test.
resource "env0_environment_state_access" "state_access" {
environment_id = env0_environment.example.id
allowed_project_ids = [env0_project.test_project.id]
/* TODO
resource "env0_environment_state_access" "disallow" {
environment_id = env0_environment.example.id
accessible_from_entire_organization = false
allowed_project_ids = []
}
*/

Expand Down

0 comments on commit 1fa7a0e

Please sign in to comment.