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

New resource: wiz_saml_group_mapping #216

Merged
merged 22 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9a46a77
add resource wiz_saml_group_mapping
NerdJeremia Jul 26, 2024
2799c75
add examples and generate doc
NerdJeremia Jul 26, 2024
936f483
add acceptance test
NerdJeremia Jul 29, 2024
d166f24
format imports + upper case IDs
NerdJeremia Jul 30, 2024
7d0b941
move and rename structs
NerdJeremia Aug 6, 2024
0aca19e
rename provider group env var
NerdJeremia Aug 6, 2024
9508b34
trim graph query to read group mappings
NerdJeremia Aug 6, 2024
b293191
update resource description
NerdJeremia Aug 6, 2024
48f810f
use ProcessPagedRequest function
NerdJeremia Aug 6, 2024
b04df5b
Merge branch 'refs/heads/main' into feature/saml-group-mapping
NerdJeremia Aug 6, 2024
a96c6d5
run go generate
NerdJeremia Aug 6, 2024
a48de62
resolve linter complaints
NerdJeremia Aug 6, 2024
bac51d1
implement types as per graphql schema
NerdJeremia Aug 6, 2024
6794356
new type SAMLIdentityProviderGroupMappingsConnection
NerdJeremia Aug 7, 2024
ceaca18
rename SAMLGroupMappingDetailsInput to SAMLGroupDetailsInput + move U…
NerdJeremia Aug 8, 2024
c612da5
update schema to support multiple mappings in a set
NerdJeremia Aug 20, 2024
fb149e9
update docs
NerdJeremia Aug 20, 2024
c3ebf2c
add comment + fix imports
NerdJeremia Aug 20, 2024
f4e3141
update acceptance test
NerdJeremia Aug 20, 2024
7b1152e
single api call for create, update and delete
NerdJeremia Aug 21, 2024
3f2a9b3
set first to 500 in querySAMLGroupMappings
NerdJeremia Nov 13, 2024
0bd9af6
Merge branch 'main' into feature/saml-group-mapping
NerdJeremia Nov 13, 2024
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
124 changes: 124 additions & 0 deletions docs/resources/saml_group_mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "wiz_saml_group_mapping Resource - terraform-provider-wiz"
subcategory: ""
description: |-
Configure SAML Group Role Mapping. When using SSO to authenticate with Wiz, you can map group memberships in SAML assertions to Wiz roles across specific scopes.
---

# wiz_saml_group_mapping (Resource)

Configure SAML Group Role Mapping. When using SSO to authenticate with Wiz, you can map group memberships in SAML assertions to Wiz roles across specific scopes.

## Example Usage

```terraform
# Configure SAML Group Role Mapping on a global scope
resource "wiz_saml_group_mapping" "test_global_scope" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "global-reader-group-id"
role = "PROJECT_READER"
}
]
}

# Configure SAML Group Role Mapping for a single project
resource "wiz_saml_group_mapping" "test_single_project" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "admin-group-id"
role = "PROJECT_ADMIN"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786"
]
}
]
}

# Configure SAML Group Role Mapping for multiple projects
resource "wiz_saml_group_mapping" "test_multi_project" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "member-group-id"
role = "PROJECT_MEMBER"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786",
"e7f6542c-81f6-43cf-af48-bdd77f09650d"
]
}
]
}

# Configure multiple SAML Group Role Mappings
resource "wiz_saml_group_mapping" "test_multi_mappings" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "global-reader-group-id"
role = "PROJECT_READER"
},
{
provider_group_id = "admin-group-id"
role = "PROJECT_ADMIN"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786"
]
},
{
provider_group_id = "member-group-id"
role = "PROJECT_MEMBER"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786",
"e7f6542c-81f6-43cf-af48-bdd77f09650d"
]
}
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `group_mapping` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--group_mapping))
- `saml_idp_id` (String) Identifier for the Saml Provider

### Read-Only

- `id` (String) Unique tf-internal identifier for the saml group mapping

<a id="nestedblock--group_mapping"></a>
### Nested Schema for `group_mapping`

Required:

- `provider_group_id` (String) Provider group ID
- `role` (String) Wiz Role name

Optional:

- `projects` (List of String) Project mapping

## Import

Import is supported using the following syntax:

```shell
# The id for importing resources has to be in this format: 'mapping|<saml_idp_id>|<provider_group_id>:<project_ids>:<role>#...'.
# Import with saml mapping to multiple projects
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a,ee25cc95-82b0-4543-8934-5bc655b86786:PROJECT_READER"

# Import with mapping to single project
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a:PROJECT_READER"

# Import with global mapping
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7::PROJECT_READER"

# Import with multiple group mappings
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a:PROJECT_READER#12345678-1234-1234-1234-123456789012:ee25cc95-82b0-4543-8934-5bc655b86786:PROJECT_WRITER"
```
12 changes: 12 additions & 0 deletions examples/resources/wiz_saml_group_mapping/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# The id for importing resources has to be in this format: 'mapping|<saml_idp_id>|<provider_group_id>:<project_ids>:<role>#...'.
# Import with saml mapping to multiple projects
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a,ee25cc95-82b0-4543-8934-5bc655b86786:PROJECT_READER"

# Import with mapping to single project
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a:PROJECT_READER"

# Import with global mapping
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7::PROJECT_READER"

# Import with multiple group mappings
terraform import wiz_saml_group_mapping.example_import "mapping|wiz-azure-ad-saml|88990357-fe36-421b-aedc-fcdd602b91d7:bb62aac7-e8bd-5d5e-b205-2dbafe106e1a:PROJECT_READER#12345678-1234-1234-1234-123456789012:ee25cc95-82b0-4543-8934-5bc655b86786:PROJECT_WRITER"
65 changes: 65 additions & 0 deletions examples/resources/wiz_saml_group_mapping/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Configure SAML Group Role Mapping on a global scope
resource "wiz_saml_group_mapping" "test_global_scope" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "global-reader-group-id"
role = "PROJECT_READER"
}
]
}

# Configure SAML Group Role Mapping for a single project
resource "wiz_saml_group_mapping" "test_single_project" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "admin-group-id"
role = "PROJECT_ADMIN"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786"
]
}
]
}

# Configure SAML Group Role Mapping for multiple projects
resource "wiz_saml_group_mapping" "test_multi_project" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "member-group-id"
role = "PROJECT_MEMBER"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786",
"e7f6542c-81f6-43cf-af48-bdd77f09650d"
]
}
]
}

# Configure multiple SAML Group Role Mappings
resource "wiz_saml_group_mapping" "test_multi_mappings" {
saml_idp_id = "test-saml-identity-provider"
group_mappings = [
{
provider_group_id = "global-reader-group-id"
role = "PROJECT_READER"
},
{
provider_group_id = "admin-group-id"
role = "PROJECT_ADMIN"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786"
]
},
{
provider_group_id = "member-group-id"
role = "PROJECT_MEMBER"
projects = [
"ee25cc95-82b0-4543-8934-5bc655b86786",
"e7f6542c-81f6-43cf-af48-bdd77f09650d"
]
}
]
}
2 changes: 2 additions & 0 deletions internal/acceptance/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ const (
TcCloudConfigRule TestCase = "CLOUD_CONFIG_RULE"
// TcProjectCloudAccountLink test case
TcProjectCloudAccountLink = "PROJECT_CLOUD_ACCOUNT_LINK"
// TcSAMLGroupMapping test case
TcSAMLGroupMapping TestCase = "SAML_GROUP_MAPPING"
)
2 changes: 2 additions & 0 deletions internal/acceptance/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func testAccPreCheck(t *testing.T, tc TestCase) {
envVars = append(commonEnvVars, "WIZ_PROJECT_ID")
case TcProjectCloudAccountLink:
envVars = append(commonEnvVars, "WIZ_PROJECT_ID", "WIZ_SUBSCRIPTION_ID")
case TcSAMLGroupMapping:
envVars = append(commonEnvVars, "WIZ_PROJECT_ID", "WIZ_PROVIDER_GROUP_ID", "WIZ_SAML_IDP_ID")
default:
t.Fatalf("unknown testCase: %s", tc)
}
Expand Down
56 changes: 56 additions & 0 deletions internal/acceptance/resource_saml_group_mapping_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package acceptance

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccResourceWizSAMLGroupMapping_basic(t *testing.T) {
samlIdpID := os.Getenv("WIZ_SAML_IDP_ID")
providerGroupID := os.Getenv("WIZ_PROVIDER_GROUP_ID")
projectID := os.Getenv("WIZ_PROJECT_ID")

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, TcSAMLGroupMapping) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testResourceWizSAMLGroupMappingBasic(samlIdpID, providerGroupID, projectID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"wiz_saml_group_mapping.foo",
"saml_idp_id",
samlIdpID,
),
resource.TestCheckResourceAttr(
"wiz_saml_group_mapping.foo",
"group_mapping.0.provider_group_id",
providerGroupID,
),
resource.TestCheckResourceAttr(
"wiz_saml_group_mapping.foo",
"group_mapping.0.projects.0",
projectID,
),
),
},
},
})
}

func testResourceWizSAMLGroupMappingBasic(samlIdpID string, providerGroupID string, projectID string) string {
return fmt.Sprintf(`
resource "wiz_saml_group_mapping" "foo" {
saml_idp_id = "%s"
group_mapping {
provider_group_id = "%s"
role = "PROJECT_READER"
projects = [
"%s"
]
}
}`, samlIdpID, providerGroupID, projectID)
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ yLyKQXhw2W2Xs0qLeC1etA+jTGDK4UfLeC0SF7FSi8o5LL21L8IzApar2pR/
"wiz_report_graph_query": resourceWizReportGraphQuery(),
"wiz_project": resourceWizProject(),
"wiz_saml_idp": resourceWizSAMLIdP(),
"wiz_saml_group_mapping": resourceWizSAMLGroupMapping(),
"wiz_security_framework": resourceWizSecurityFramework(),
"wiz_service_account": resourceWizServiceAccount(),
"wiz_user": resourceWizUser(),
Expand Down
Loading