Skip to content

Commit

Permalink
HCPIE-1016: Adding and adjusting subcategories for IAM stuff (hashico…
Browse files Browse the repository at this point in the history
…rp#797)

* adding and adjusting subcategories for iam stuff

* changelog

* add context and org id to iam calls

* add bug to changelog

* undo previous sub category change

* add docs to changelog
  • Loading branch information
itsjaspermilan authored Mar 22, 2024
1 parent 84a64f4 commit 5fd52fd
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changelog/797.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:improvement
Documentation: Adjust the subcategory for hcp_user_principal, hcp_group_members, hcp_iam_workload_identity_provider to Cloud Platform
```

```release-note:bug
Fixes an issue where organization ID was not sent on data.hcp_user_principal lookup
```
13 changes: 11 additions & 2 deletions docs/data-sources/user_principal.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "hcp_user_principal Data Source - terraform-provider-hcp"
subcategory: ""
subcategory: "Cloud Platform"
description: |-
The user principal data source retrieves the given user principal.
---
Expand All @@ -10,7 +9,17 @@ description: |-

The user principal data source retrieves the given user principal.

## Example Usage

```terraform
data "hcp_user_principal" "example" {
user_id = var.example_user_id
}
data "hcp_user_principal" "example" {
email = var.example_email
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
3 changes: 1 addition & 2 deletions docs/resources/group_members.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "hcp_group_members Resource - terraform-provider-hcp"
subcategory: ""
subcategory: "Cloud Platform"
description: |-
The group members resource manages the members of an HCP Group.
The user or service account that is running Terraform when creating an hcp_group_members resource must have roles/admin on the organization.
Expand Down
7 changes: 7 additions & 0 deletions examples/data-sources/hcp_user_principal/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "hcp_user_principal" "example" {
user_id = var.example_user_id
}

data "hcp_user_principal" "example" {
email = var.example_email
}
6 changes: 3 additions & 3 deletions internal/provider/iam/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (d *DataSourceGroup) Read(ctx context.Context, req datasource.ReadRequest,
return
}

getParams := groups_service.NewGroupsServiceGetGroupParams()
getParams.ResourceName = data.ResourceName.ValueString()
getParams := groups_service.NewGroupsServiceGetGroupParamsWithContext(ctx)
getParams.SetResourceName(data.ResourceName.ValueString())

// if shorthand resourceName was provided, generate full resourceName
if !strings.HasPrefix(getParams.ResourceName, "iam/") {
orgID := d.client.Config.OrganizationID
getParams.ResourceName = fmt.Sprintf("iam/organization/%s/group/%s", orgID, data.ResourceName.ValueString())
getParams.SetResourceName(fmt.Sprintf("iam/organization/%s/group/%s", orgID, data.ResourceName.ValueString()))
}

res, err := d.client.Groups.GroupsServiceGetGroup(getParams, nil)
Expand Down
8 changes: 5 additions & 3 deletions internal/provider/iam/data_user_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func (d *DataSourceUserPrincipal) Read(ctx context.Context, req datasource.ReadR
return
} else if !data.UserID.IsNull() {
// Get the user principal by ID.
getParams := iam_service.NewIamServiceGetUserPrincipalByIDInOrganizationParams()
getParams.UserPrincipalID = data.UserID.ValueString()
getParams := iam_service.NewIamServiceGetUserPrincipalByIDInOrganizationParamsWithContext(ctx)
getParams.SetUserPrincipalID(data.UserID.ValueString())
getParams.SetOrganizationID(d.client.Config.OrganizationID)

res, err := d.client.IAM.IamServiceGetUserPrincipalByIDInOrganization(getParams, nil)
if err != nil {
Expand All @@ -115,7 +116,8 @@ func (d *DataSourceUserPrincipal) Read(ctx context.Context, req datasource.ReadR
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
} else if !data.Email.IsNull() {
// Search for the user principal by email.
getParams := iam_service.NewIamServiceSearchPrincipalsParams()
getParams := iam_service.NewIamServiceSearchPrincipalsParamsWithContext(ctx)
getParams.SetOrganizationID(d.client.Config.OrganizationID)
getParams.SetBody(iam_service.IamServiceSearchPrincipalsBody{
Filter: &models.HashicorpCloudIamSearchPrincipalsFilter{
SearchText: data.Email.ValueString(),
Expand Down
16 changes: 16 additions & 0 deletions templates/data-sources/user_principal.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: "Cloud Platform"
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

## Example Usage

{{ tffile "examples/data-sources/hcp_user_principal/data-source.tf" }}

{{ .SchemaMarkdown | trimspace }}
22 changes: 22 additions & 0 deletions templates/resources/group_members.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: "Cloud Platform"
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

## Example Usage

{{ tffile "examples/resources/hcp_group_members/resource.tf" }}

{{ .SchemaMarkdown | trimspace }}

## Import

Import is supported using the following syntax:

{{codefile "shell" "examples/resources/hcp_group_members/import.sh" }}

0 comments on commit 5fd52fd

Please sign in to comment.