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

Creating ns1_user with security_manage_global_2fa true even if set to false #170

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ns1/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,13 @@ func resourceDataToPermissions(d *schema.ResourceData) account.PermissionsMap {
if v, ok := d.GetOk("monitoring_view_jobs"); ok {
p.Monitoring.ViewJobs = v.(bool)
}
if p.Security == nil {
p.Security = &account.PermissionsSecurity{}
}
if v, ok := d.GetOk("security_manage_global_2fa"); ok {
if p.Security == nil {
p.Security = &account.PermissionsSecurity{}
}
p.Security.ManageGlobal2FA = v.(bool)
}
if v, ok := d.GetOk("security_manage_active_directory"); ok {
if p.Security == nil {
p.Security = &account.PermissionsSecurity{}
}
p.Security.ManageActiveDirectory = v.(bool)
}
if v, ok := d.GetOk("dhcp_manage_dhcp"); ok {
Expand Down
33 changes: 33 additions & 0 deletions ns1/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ func TestAccUser_permissions(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
{
Config: testAccUserSecurityPermissionsNoTeam(rString),
Check: resource.ComposeTestCheckFunc(
testAccCheckUserExists("ns1_user.u", &user),
resource.TestCheckResourceAttr("ns1_user.u", "email", "[email protected]"),
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "security_manage_global_2fa", "false"),
),
},
{
Config: testAccUserPermissionsOnTeam(rString),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -671,6 +683,27 @@ resource "ns1_user" "u" {
`, rString, rString, rString)
}

func testAccUserSecurityPermissionsNoTeam(rString string) string {
return fmt.Sprintf(`resource "ns1_team" "t" {
name = "terraform acc test team %s"
account_manage_account_settings = true
}

resource "ns1_user" "u" {
name = "terraform acc test user %s"
username = "tf_acc_test_user_%s"
email = "[email protected]"

notify = {
billing = false
}

account_manage_ip_whitelist = true
security_manage_global_2fa = false
}
`, rString, rString, rString)
}

// Explicitly sets the users team to []
func testAccUserPermissionsEmptyTeam(rString string) string {
return fmt.Sprintf(`resource "ns1_team" "t" {
Expand Down