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

Add add_vpcs and add_placement_groups user grants #1720

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ The Linode User resource exports the following attributes:

* [`nodebalancer_grant`](#grant) - The grants this User has pertaining to NodeBalancers on this Account.

* [`placement_group_grant`](#grant) - The grants this User has pertaining to Placement Groups on this Account.

* [`stackscript_grant`](#grant) - The grants this User has pertaining to StackScripts on this Account.

* [`volume_grant`](#grant) - The grants this User has pertaining to Volumes on this Account.

* [`vpc_grant`](#grant) - The grants this User has pertaining to Virtual Private Clouds (VPCs) on this Account.

* `id` - The unique identifier for this DataSource.

* `password_created` - The date and time when this User’s current password was created. User passwords are first created during the Account sign-up process, and updated using the Reset Password webpage. null if this User has not created a password yet.
Expand All @@ -95,10 +99,14 @@ The Linode User resource exports the following attributes:

* `add_nodebalancers` - If true, this User may add NodeBalancers.

* `add_placement_groups` - If true, this User may add Placement Groups.

* `add_stackscritps` - If true, this User may add StackScripts.

* `add_volumes` - If true, this User may add Volumes.

* `add_vpcs` - If true, this User may add Virtual Private Clouds (VPCs).

* `cancel_account` - If true, this User may cancel the entire Account.

* `longview_subscription` - If true, this User may manage the Account’s Longview subscription.
Expand Down
8 changes: 8 additions & 0 deletions docs/data-sources/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ Each Linode user will be stored in the `users` attribute and will export the fol

* [`nodebalancer_grant`](#grant) - The grants this User has pertaining to NodeBalancers on this Account.

* [`placement_group_grant`](#grant) - The grants this User has pertaining to Placement Groups on this Account.

* [`stackscript_grant`](#grant) - The grants this User has pertaining to StackScripts on this Account.

* [`volume_grant`](#grant) - The grants this User has pertaining to Volumes on this Account.

* [`vpc_grant`](#grant) - The grants this User has pertaining to Virtual Private Clouds (VPCs) on this Account.

* `id` - The unique identifier for this DataSource.

* `password_created` - The date and time when this User’s current password was created. User passwords are first created during the Account sign-up process, and updated using the Reset Password webpage. null if this User has not created a password yet.
Expand All @@ -100,10 +104,14 @@ Each Linode user will be stored in the `users` attribute and will export the fol

* `add_nodebalancers` - If true, this User may add NodeBalancers.

* `add_placement_groups` - If true, this User may add Placement Groups.

* `add_stackscritps` - If true, this User may add StackScripts.

* `add_volumes` - If true, this User may add Volumes.

* `add_vpcs` - If true, this User may add Virtual Private Clouds (VPCs).

* `cancel_account` - If true, this User may cancel the entire Account.

* `longview_subscription` - If true, this User may manage the Account’s Longview subscription.
Expand Down
8 changes: 8 additions & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ The following arguments are sets of [entity grants](#entity-grants):

* `nodebalancer_grant` - (optional) The NodeBalancers the user has permissions access to.

* `placement_group_grant` - (optional) The Placement Groups the user has permissions access to.

* `stackscript_grant` - (optional) The StackScripts the user has permissions access to.

* `volume_grant` - (optional) The volumes the user has permissions access to.

* `vpc_grant` - (optional) The Virtual Private Clouds (VPCs) the user has permissions access to.

## Attributes Reference

In addition to all the arguments above, the following attributes are exported.
Expand Down Expand Up @@ -98,8 +102,12 @@ In addition to all the arguments above, the following attributes are exported.

* `add_nodebalancers` - (optional) If true, this User may add NodeBalancers.

* `add_placement_groups` - (optional) If true, this User may add Placement Groups.

* `add_stackscripts` - (optional) If true, this User may add StackScripts.

* `add_vpcs` - (optional) If true, this User may add Virtual Private Clouds (VPCs).

* `cancel_account` - (optional) If true, this User may cancel the entire Account.

* `longview_subscription` - (optional) If true, this User may manage the Account’s Longview subscription.
Expand Down
2 changes: 2 additions & 0 deletions linode/user/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ func TestAccDataSourceUser_grants(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "linode_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "longview_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "nodebalancer_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "placement_group_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "stackscript_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "volume_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "vpc_grant.#"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions linode/user/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func flattenGrantsGlobal(global *linodego.GlobalUserGrants) map[string]interface
result["add_linodes"] = global.AddLinodes
result["add_longview"] = global.AddLongview
result["add_nodebalancers"] = global.AddNodeBalancers
result["add_placement_groups"] = global.AddPlacementGroups
result["add_stackscripts"] = global.AddStackScripts
result["add_volumes"] = global.AddVolumes
result["add_vpcs"] = global.AddVPCs
result["cancel_account"] = global.CancelAccount
result["longview_subscription"] = global.LongviewSubscription

Expand Down
22 changes: 13 additions & 9 deletions linode/user/framework_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var linodeUserGrantsGlobalObjectType = types.ObjectType{
"add_linodes": types.BoolType,
"add_longview": types.BoolType,
"add_nodebalancers": types.BoolType,
"add_placement_groups": types.BoolType,
"add_stackscripts": types.BoolType,
"add_volumes": types.BoolType,
"add_vpcs": types.BoolType,
"cancel_account": types.BoolType,
"longview_subscription": types.BoolType,
},
Expand Down Expand Up @@ -69,15 +71,17 @@ var UserAttributes = map[string]schema.Attribute{
Computed: true,
ElementType: linodeUserGrantsGlobalObjectType,
},
"database_grant": linodeUserGrantsEntitySet,
"domain_grant": linodeUserGrantsEntitySet,
"firewall_grant": linodeUserGrantsEntitySet,
"image_grant": linodeUserGrantsEntitySet,
"linode_grant": linodeUserGrantsEntitySet,
"longview_grant": linodeUserGrantsEntitySet,
"nodebalancer_grant": linodeUserGrantsEntitySet,
"stackscript_grant": linodeUserGrantsEntitySet,
"volume_grant": linodeUserGrantsEntitySet,
"database_grant": linodeUserGrantsEntitySet,
"domain_grant": linodeUserGrantsEntitySet,
"firewall_grant": linodeUserGrantsEntitySet,
"image_grant": linodeUserGrantsEntitySet,
"linode_grant": linodeUserGrantsEntitySet,
"longview_grant": linodeUserGrantsEntitySet,
"nodebalancer_grant": linodeUserGrantsEntitySet,
"placement_group_grant": linodeUserGrantsEntitySet,
"stackscript_grant": linodeUserGrantsEntitySet,
"volume_grant": linodeUserGrantsEntitySet,
"vpc_grant": linodeUserGrantsEntitySet,
"id": schema.StringAttribute{
Description: "Unique identifier for this DataSource.",
Computed: true,
Expand Down
4 changes: 4 additions & 0 deletions linode/user/framework_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type DataSourceModel struct {
LinodeGrant types.Set `tfsdk:"linode_grant"`
LongviewGrant types.Set `tfsdk:"longview_grant"`
NodebalancerGrant types.Set `tfsdk:"nodebalancer_grant"`
PlacementGroupGrant types.Set `tfsdk:"placement_group_grant"`
StackscriptGrant types.Set `tfsdk:"stackscript_grant"`
VolumeGrant types.Set `tfsdk:"volume_grant"`
VPCGrant types.Set `tfsdk:"vpc_grant"`
DatabaseGrant types.Set `tfsdk:"database_grant"`
ID types.String `tfsdk:"id"`
PasswordCreated types.String `tfsdk:"password_created"`
Expand Down Expand Up @@ -175,8 +177,10 @@ func flattenGlobalGrants(ctx context.Context, grants linodego.GlobalUserGrants)
result["add_linodes"] = types.BoolValue(grants.AddLinodes)
result["add_longview"] = types.BoolValue(grants.AddLongview)
result["add_nodebalancers"] = types.BoolValue(grants.AddNodeBalancers)
result["add_placement_groups"] = types.BoolValue(grants.AddPlacementGroups)
result["add_stackscripts"] = types.BoolValue(grants.AddStackScripts)
result["add_volumes"] = types.BoolValue(grants.AddVolumes)
result["add_vpcs"] = types.BoolValue(grants.AddVPCs)
result["cancel_account"] = types.BoolValue(grants.CancelAccount)
result["longview_subscription"] = types.BoolValue(grants.LongviewSubscription)

Expand Down
4 changes: 4 additions & 0 deletions linode/user/framework_models_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ func TestParseUserGrants(t *testing.T) {
AddLinodes: true,
AddLongview: true,
AddNodeBalancers: true,
AddPlacementGroups: true,
AddStackScripts: true,
AddVolumes: true,
AddVPCs: true,
CancelAccount: false,
LongviewSubscription: true,
},
Expand Down Expand Up @@ -147,8 +149,10 @@ func TestParseUserGrants(t *testing.T) {
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_linodes\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_longview\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_nodebalancers\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_placement_groups\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_stackscripts\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_volumes\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"add_vpcs\":true")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"cancel_account\":false")
assert.Contains(t, dataModel.GlobalGrants.String(), "\"longview_subscription\":true")
}
4 changes: 4 additions & 0 deletions linode/user/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func readResource(ctx context.Context, d *schema.ResourceData, meta interface{})
d.Set("linode_grant", flattenGrantsEntities(grants.Linode))
d.Set("longview_grant", flattenGrantsEntities(grants.Longview))
d.Set("nodebalancer_grant", flattenGrantsEntities(grants.NodeBalancer))
d.Set("placement_group_grant", flattenGrantsEntities(grants.PlacementGroup))
d.Set("stackscript_grant", flattenGrantsEntities(grants.StackScript))
d.Set("volume_grant", flattenGrantsEntities(grants.Volume))
d.Set("vpc_grant", flattenGrantsEntities(grants.VPC))
}

d.Set("username", username)
Expand Down Expand Up @@ -235,8 +237,10 @@ func expandGrantsGlobal(global map[string]interface{}) linodego.GlobalUserGrants
result.AddLinodes = global["add_linodes"].(bool)
result.AddLongview = global["add_longview"].(bool)
result.AddNodeBalancers = global["add_nodebalancers"].(bool)
result.AddPlacementGroups = global["add_placement_groups"].(bool)
result.AddStackScripts = global["add_stackscripts"].(bool)
result.AddVolumes = global["add_volumes"].(bool)
result.AddVPCs = global["add_vpcs"].(bool)
result.CancelAccount = global["cancel_account"].(bool)
result.LongviewSubscription = global["longview_subscription"].(bool)

Expand Down
4 changes: 4 additions & 0 deletions linode/user/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ func TestAccResourceUser_grants(t *testing.T) {
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_linodes", "true"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_longview", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_nodebalancers", "true"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_placement_groups", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_stackscripts", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_volumes", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_vpcs", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.cancel_account", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.longview_subscription", "false"),
resource.TestCheckResourceAttr(testUserResName, "linode_grant.#", "0"),
Expand All @@ -119,8 +121,10 @@ func TestAccResourceUser_grants(t *testing.T) {
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_linodes", "true"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_longview", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_nodebalancers", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_placement_groups", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_stackscripts", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_volumes", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.add_vpcs", "false"),
Copy link
Author

Choose a reason for hiding this comment

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

This file is what give me the most uncertainty. I confess to not digging to far into how it worked and just chose "false" in both cases.

resource.TestCheckResourceAttr(testUserResName, "global_grants.0.cancel_account", "false"),
resource.TestCheckResourceAttr(testUserResName, "global_grants.0.longview_subscription", "false"),
resource.TestCheckResourceAttr(testUserResName, "linode_grant.#", "1"),
Expand Down
30 changes: 22 additions & 8 deletions linode/user/schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ var resourceSchema = map[string]*schema.Schema{
MaxItems: 1,
Elem: resourceLinodeUserGrantsGlobal(),
},
"domain_grant": resourceLinodeUserGrantsEntitySet(),
"firewall_grant": resourceLinodeUserGrantsEntitySet(),
"image_grant": resourceLinodeUserGrantsEntitySet(),
"linode_grant": resourceLinodeUserGrantsEntitySet(),
"longview_grant": resourceLinodeUserGrantsEntitySet(),
"nodebalancer_grant": resourceLinodeUserGrantsEntitySet(),
"stackscript_grant": resourceLinodeUserGrantsEntitySet(),
"volume_grant": resourceLinodeUserGrantsEntitySet(),
"domain_grant": resourceLinodeUserGrantsEntitySet(),
"firewall_grant": resourceLinodeUserGrantsEntitySet(),
"image_grant": resourceLinodeUserGrantsEntitySet(),
"linode_grant": resourceLinodeUserGrantsEntitySet(),
"longview_grant": resourceLinodeUserGrantsEntitySet(),
"nodebalancer_grant": resourceLinodeUserGrantsEntitySet(),
"placement_group_grant": resourceLinodeUserGrantsEntitySet(),
"stackscript_grant": resourceLinodeUserGrantsEntitySet(),
"volume_grant": resourceLinodeUserGrantsEntitySet(),
"vpc_grant": resourceLinodeUserGrantsEntitySet(),
}

func resourceLinodeUserGrantsGlobal() *schema.Resource {
Expand Down Expand Up @@ -105,6 +107,12 @@ func resourceLinodeUserGrantsGlobal() *schema.Resource {
Optional: true,
Default: false,
},
"add_placement_groups": {
Type: schema.TypeBool,
Description: "If true, this User may add Placement Groups.",
Optional: true,
Default: false,
},
"add_stackscripts": {
Type: schema.TypeBool,
Description: "If true, this User may add StackScripts.",
Expand All @@ -117,6 +125,12 @@ func resourceLinodeUserGrantsGlobal() *schema.Resource {
Optional: true,
Default: false,
},
"add_vpcs": {
Type: schema.TypeBool,
Description: "If true, this User may add Virtual Private Clouds (VPCs).",
Optional: true,
Default: false,
},
"cancel_account": {
Type: schema.TypeBool,
Description: "If true, this User may cancel the entire Account.",
Expand Down
2 changes: 2 additions & 0 deletions linode/users/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func TestAccDataSourceUsers_clientFilter(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "users.0.linode_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.longview_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.nodebalancer_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.placement_group_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.stackscript_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.volume_grant.#"),
resource.TestCheckResourceAttrSet(resourceName, "users.0.vpc_grant.#"),
),
},
},
Expand Down