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

CORE-656/Add manage_ip_whitelist permission to account section #148

Merged
merged 4 commits into from
Mar 5, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.9.3 (March 4, 2021)
BUG FIXES:
* Adds missing `account_manage_ip_whitelist` permission [#148](https://github.com/ns1-terraform/terraform-provider-ns1/pull/148).

## 1.9.2 (February 26, 2021)
BUG FIXES:
* Values for `tls_skip_verify` are coerced correctly [#146](https://github.com/ns1-terraform/terraform-provider-ns1/pull/146). Thanks @zahiar!
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ns1/ns1-go.v2 v2.4.2
gopkg.in/ns1/ns1-go.v2 v2.4.4
gopkg.in/yaml.v2 v2.2.7 // indirect
)

Expand Down
37 changes: 4 additions & 33 deletions go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ns1/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func addPermsSchema(s map[string]*schema.Schema) map[string]*schema.Schema {
Default: false,
DiffSuppressFunc: suppressPermissionDiff,
}
s["account_manage_ip_whitelist"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
DiffSuppressFunc: suppressPermissionDiff,
}
s["monitoring_manage_lists"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -209,6 +215,7 @@ func permissionsToResourceData(d *schema.ResourceData, permissions account.Permi
d.Set("account_manage_account_settings", permissions.Account.ManageAccountSettings)
d.Set("account_view_activity_log", permissions.Account.ViewActivityLog)
d.Set("account_view_invoices", permissions.Account.ViewInvoices)
d.Set("account_manage_ip_whitelist", permissions.Account.ManageIPWhitelist)
d.Set("monitoring_manage_lists", permissions.Monitoring.ManageLists)
d.Set("monitoring_manage_jobs", permissions.Monitoring.ManageJobs)
d.Set("monitoring_view_jobs", permissions.Monitoring.ViewJobs)
Expand Down Expand Up @@ -288,6 +295,9 @@ func resourceDataToPermissions(d *schema.ResourceData) account.PermissionsMap {
if v, ok := d.GetOk("account_view_invoices"); ok {
p.Account.ViewInvoices = v.(bool)
}
if v, ok := d.GetOk("account_manage_ip_whitelist"); ok {
p.Account.ManageIPWhitelist = v.(bool)
}
if v, ok := d.GetOk("monitoring_manage_lists"); ok {
p.Monitoring.ManageLists = v.(bool)
}
Expand Down
6 changes: 6 additions & 0 deletions ns1/permissions_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func addPermsSchemaV0(s map[string]*schema.Schema) map[string]*schema.Schema {
Default: false,
DiffSuppressFunc: suppressPermissionDiff,
}
s["account_manage_ip_whitelist"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
DiffSuppressFunc: suppressPermissionDiff,
}
s["monitoring_manage_lists"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions ns1/resource_apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestAccAPIKey_permissions(t *testing.T) {
testAccCheckAPIKeyName(&apiKey, name),
// The key should still have this permission, it would have inherited it from the team.
resource.TestCheckResourceAttr("ns1_apikey.it", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_apikey.it", "account_manage_ip_whitelist", "true"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -137,6 +138,7 @@ func TestAccAPIKey_permissions(t *testing.T) {
testAccCheckAPIKeyName(&apiKey, name),
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_apikey.it", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_apikey.it", "account_manage_ip_whitelist", "false"),
),
},
},
Expand Down Expand Up @@ -246,6 +248,7 @@ func testAccAPIKeyPermissionsOnTeam(rString string) string {
return fmt.Sprintf(`resource "ns1_team" "t" {
name = "terraform acc test team %s"
account_manage_account_settings = true
account_manage_ip_whitelist = true
sergey-kreytor marked this conversation as resolved.
Show resolved Hide resolved
}

resource "ns1_apikey" "it" {
Expand All @@ -261,6 +264,7 @@ func testAccAPIKeyPermissionsNoTeam(rString string) string {
return fmt.Sprintf(`resource "ns1_team" "t" {
name = "terraform acc test team %s"
account_manage_account_settings = true
account_manage_ip_whitelist = true
}

resource "ns1_apikey" "it" {
Expand Down
27 changes: 27 additions & 0 deletions ns1/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestAccUser_permissions(t *testing.T) {
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"),
),
},
{
Expand All @@ -118,6 +119,7 @@ func TestAccUser_permissions(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
{
Expand All @@ -129,6 +131,7 @@ func TestAccUser_permissions(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
// The user should still have this permission, it would have inherited it from the team.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -141,6 +144,7 @@ func TestAccUser_permissions(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
},
Expand All @@ -166,6 +170,7 @@ func TestAccUser_permissions_empty_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
// Strange Terraform behavior causes explicitly settings a users team to []
Expand All @@ -178,6 +183,7 @@ func TestAccUser_permissions_empty_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -190,6 +196,7 @@ func TestAccUser_permissions_empty_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
},
Expand All @@ -216,6 +223,7 @@ func TestAccUser_permissions_start_no_team(t *testing.T) {
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"),
),
},
{
Expand All @@ -226,6 +234,7 @@ func TestAccUser_permissions_start_no_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
{
Expand All @@ -237,6 +246,7 @@ func TestAccUser_permissions_start_no_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
// The user should still have this permission, it would have inherited it from the team.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -249,6 +259,7 @@ func TestAccUser_permissions_start_no_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
},
Expand All @@ -275,6 +286,7 @@ func TestAccUser_permissions_multiple_teams(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "name", name),
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
{
Expand All @@ -286,6 +298,7 @@ func TestAccUser_permissions_multiple_teams(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
{
Expand All @@ -297,6 +310,7 @@ func TestAccUser_permissions_multiple_teams(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
{
Expand All @@ -309,6 +323,7 @@ func TestAccUser_permissions_multiple_teams(t *testing.T) {
// The user should still have this permission, it would have inherited it from the team.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -322,6 +337,7 @@ func TestAccUser_permissions_multiple_teams(t *testing.T) {
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
},
Expand All @@ -348,6 +364,7 @@ func TestAccUser_permissions_multiple_teams_start_no_team(t *testing.T) {
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"),
),
},
{
Expand All @@ -359,6 +376,7 @@ func TestAccUser_permissions_multiple_teams_start_no_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
{
Expand All @@ -370,6 +388,7 @@ func TestAccUser_permissions_multiple_teams_start_no_team(t *testing.T) {
resource.TestCheckResourceAttr("ns1_user.u", "username", username),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
},
{
Expand All @@ -382,6 +401,7 @@ func TestAccUser_permissions_multiple_teams_start_no_team(t *testing.T) {
// The user should still have this permission, it would have inherited it from the team.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "true"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "false"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -395,6 +415,7 @@ func TestAccUser_permissions_multiple_teams_start_no_team(t *testing.T) {
// But if an apply is ran again, the permission will be removed.
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_account_settings", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_apikeys", "false"),
resource.TestCheckResourceAttr("ns1_user.u", "account_manage_ip_whitelist", "true"),
),
},
},
Expand Down Expand Up @@ -613,6 +634,7 @@ func testAccUserPermissionsOnTeam(rString string) string {
return fmt.Sprintf(`resource "ns1_team" "t" {
name = "terraform acc test team %s"
account_manage_account_settings = true
account_manage_ip_whitelist = false
}

resource "ns1_user" "u" {
Expand Down Expand Up @@ -643,6 +665,8 @@ resource "ns1_user" "u" {
notify = {
billing = false
}

account_manage_ip_whitelist = true
}
`, rString, rString, rString)
}
Expand Down Expand Up @@ -677,6 +701,7 @@ func testAccUserPermissionsOnTwoTeam(rString string) string {
resource "ns1_team" "t2" {
name = "terraform acc test team %s-2"
account_manage_apikeys = true
account_manage_ip_whitelist = true
}

resource "ns1_user" "u" {
Expand All @@ -689,6 +714,8 @@ resource "ns1_user" "u" {
notify = {
billing = false
}

account_manage_ip_whitelist = true
}
`, rString, rString, rString, rString)
}
12 changes: 11 additions & 1 deletion vendor/gopkg.in/ns1/ns1-go.v2/rest/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading