-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user attribute member resource (#44)
* Add user attribute member resource * Documentation generation * Remove import method; N/A
- Loading branch information
1 parent
e7be987
commit 7c7e020
Showing
8 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
page_title: "looker_user_attribute_member Resource - terraform-provider-looker" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
# looker_user_attribute_member (Resource) | ||
|
||
## Example Usage | ||
```terraform | ||
resource "looker_user_attribute" "att" { | ||
name = "attribute_name" | ||
label = "attribute label" | ||
type = "string" | ||
} | ||
resource "looker_group" "my-group" { | ||
name = "mygroup" | ||
} | ||
resource "looker_user_attribute_member" "name" { | ||
user_attribute_id = looker_user_attribute.att.id | ||
group { | ||
id = looker_group.my-group.id | ||
value = "attribute-value" | ||
} | ||
} | ||
``` | ||
|
||
## Example Output | ||
```terraform | ||
% terraform show | ||
# looker_group.my-group: | ||
resource "looker_group" "my-group" { | ||
delete_on_destroy = true | ||
id = "39" | ||
name = "mygroup" | ||
parent_groups = [] | ||
roles = [] | ||
} | ||
# looker_user_attribute.att: | ||
resource "looker_user_attribute" "att" { | ||
id = "35" | ||
label = "attribute label" | ||
name = "attribute_name" | ||
type = "string" | ||
user_can_edit = true | ||
user_can_view = true | ||
value_is_hidden = false | ||
} | ||
# looker_user_attribute_member.name: | ||
resource "looker_user_attribute_member" "name" { | ||
id = "-" | ||
user_attribute_id = "35" | ||
group { | ||
id = "39" | ||
name = "mygroup" | ||
value = "attribute-value" | ||
} | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `user_attribute_id` (String) | ||
|
||
### Optional | ||
|
||
- `group` (Block Set) (see [below for nested schema](#nestedblock--group)) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedblock--group"></a> | ||
### Nested Schema for `group` | ||
|
||
Required: | ||
|
||
- `value` (String) | ||
|
||
Read-Only: | ||
|
||
- `id` (String) The ID of this resource. | ||
- `name` (String) |
17 changes: 17 additions & 0 deletions
17
examples/resources/looker_user_attribute_member/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "looker_user_attribute" "att" { | ||
name = "attribute_name" | ||
label = "attribute label" | ||
type = "string" | ||
} | ||
|
||
resource "looker_group" "my-group" { | ||
name = "mygroup" | ||
} | ||
|
||
resource "looker_user_attribute_member" "name" { | ||
user_attribute_id = looker_user_attribute.att.id | ||
group { | ||
id = looker_group.my-group.id | ||
value = "attribute-value" | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
examples/resources/looker_user_attribute_member/resource.tfshow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
% terraform show | ||
# looker_group.my-group: | ||
resource "looker_group" "my-group" { | ||
delete_on_destroy = true | ||
id = "39" | ||
name = "mygroup" | ||
parent_groups = [] | ||
roles = [] | ||
} | ||
|
||
# looker_user_attribute.att: | ||
resource "looker_user_attribute" "att" { | ||
id = "35" | ||
label = "attribute label" | ||
name = "attribute_name" | ||
type = "string" | ||
user_can_edit = true | ||
user_can_view = true | ||
value_is_hidden = false | ||
} | ||
|
||
# looker_user_attribute_member.name: | ||
resource "looker_user_attribute_member" "name" { | ||
id = "-" | ||
user_attribute_id = "35" | ||
|
||
group { | ||
id = "39" | ||
name = "mygroup" | ||
value = "attribute-value" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/devoteamgcloud/terraform-provider-looker/pkg/lookergo" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceUserAttributeMember() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceUserAttributeMemberCreate, | ||
ReadContext: resourceUserAttributeMemberRead, | ||
UpdateContext: resourceUserAttributeMemberUpdate, | ||
DeleteContext: resourceUserAttributeMemberDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"user_attribute_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"group": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceUserAttributeMemberCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*Config).Api // .(*lookergo.Client) | ||
var diags diag.Diagnostics | ||
ID := d.Get("user_attribute_id").(string) | ||
groupSet, ok := d.GetOk("group") | ||
userAttrs := []lookergo.UserAttributeGroupValue{} | ||
if ok { | ||
for _, raw := range groupSet.(*schema.Set).List() { | ||
obj := raw.(map[string]interface{}) | ||
val := obj["id"].(string) | ||
att := lookergo.UserAttributeGroupValue{} | ||
att.GroupId = val | ||
att.UserAttributeId = d.Get("user_attribute_id").(string) | ||
att.Value = obj["value"].(string) | ||
userAttrs = append(userAttrs, att) | ||
} | ||
} | ||
_, _, err := c.UserAttributes.SetUserAttributeValue(ctx, userAttrs, ID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId("-") | ||
resourceUserAttributeMemberRead(ctx, d, m) | ||
return diags | ||
} | ||
|
||
func resourceUserAttributeMemberRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*Config).Api // .(*lookergo.Client) | ||
var diags diag.Diagnostics | ||
ID := d.Get("user_attribute_id").(string) | ||
attrs, _, err := c.UserAttributes.GetUserAttributeValue(ctx, ID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
var attrItems []interface{} | ||
for _, attr := range *attrs { | ||
group, _, err := c.Groups.Get(ctx, idAsInt(attr.GroupId)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
attrItems = append(attrItems, map[string]interface{}{"id": idAsString(group.Id), "name": group.Name, "value": attr.Value}) | ||
} | ||
d.Set("group", attrItems) | ||
return diags | ||
} | ||
|
||
func resourceUserAttributeMemberUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*Config).Api // .(*lookergo.Client) | ||
ID := d.Get("user_attribute_id").(string) | ||
groupSet, ok := d.GetOk("group") | ||
userAttrs := []lookergo.UserAttributeGroupValue{} | ||
if ok { | ||
for _, raw := range groupSet.(*schema.Set).List() { | ||
obj := raw.(map[string]interface{}) | ||
val := obj["id"].(string) | ||
att := lookergo.UserAttributeGroupValue{} | ||
att.GroupId = val | ||
att.UserAttributeId = d.Get("user_attribute_id").(string) | ||
att.Value = obj["value"].(string) | ||
userAttrs = append(userAttrs, att) | ||
} | ||
} | ||
_, _, err := c.UserAttributes.SetUserAttributeValue(ctx, userAttrs, ID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId("-") | ||
return resourceUserAttributeMemberRead(ctx, d, m) | ||
} | ||
|
||
func resourceUserAttributeMemberDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*Config).Api // .(*lookergo.Client) | ||
var diags diag.Diagnostics | ||
att := []lookergo.UserAttributeGroupValue{} | ||
ID := d.Get("user_attribute_id").(string) | ||
c.UserAttributes.SetUserAttributeValue(ctx, att, ID) | ||
d.SetId("") | ||
return diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters