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

Resource Enhancement: wiz_project - folder projects support #162

Merged
merged 2 commits into from
Aug 17, 2023
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
36 changes: 36 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ resource "wiz_project" "test" {
business_unit = "Technology"
}

# Folder projects example
resource "wiz_project" "root" {
name = "root"
description = "root"
is_folder = true

risk_profile {
business_impact = "MBI"
}
business_unit = "Technology"
}

resource "wiz_project" "child" {
name = "project_with_accounts"
parent_project_id = wiz_project.root.id
risk_profile {
business_impact = "MBI"
}
business_unit = "Technology"
cloud_account_link {
cloud_account_id = "477ea00a-4d4d-5bb4-9fa6-634691e68fff"
environment = "PRODUCTION"
}
}

# This resource contains multiple organization links, one with tags and another without
resource "wiz_project" "test" {
name = "Test App"
Expand Down Expand Up @@ -102,7 +127,10 @@ resource "wiz_project" "test" {
- `cloud_organization_link` (Block Set) Associate the project with an organizational link to organize all the subscription resources, issues, and findings within this project. (see [below for nested schema](#nestedblock--cloud_organization_link))
- `description` (String) The project description.
- `identifiers` (List of String) Identifiers for the project.
- `is_folder` (Boolean) Whether the project is a folder.
- Defaults to `false`.
- `kubernetes_cluster_link` (Block Set) Associate the project with kubernetes clusters. (see [below for nested schema](#nestedblock--kubernetes_cluster_link))
- `parent_project_id` (String) The parent project ID.
- `project_owners` (List of String) A list of project owner IDs.
- `risk_profile` (Block List, Max: 1) Contains risk profile related properties for the project (see [below for nested schema](#nestedblock--risk_profile))
- `security_champions` (List of String) A list of security champions IDs.
Expand Down Expand Up @@ -287,3 +315,11 @@ Optional:
- UNKNOWN

- Defaults to `UNKNOWN`.

## Import

Import is supported using the following syntax:

```shell
terraform import wiz_project.example "848025a0-9c2d-5863-8c4d-b60799294fff"
```
1 change: 1 addition & 0 deletions examples/resources/wiz_project/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import wiz_project.example "848025a0-9c2d-5863-8c4d-b60799294fff"
25 changes: 25 additions & 0 deletions examples/resources/wiz_project/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ resource "wiz_project" "test" {
business_unit = "Technology"
}

# Folder projects example
resource "wiz_project" "root" {
name = "root"
description = "root"
is_folder = true

risk_profile {
business_impact = "MBI"
}
business_unit = "Technology"
}

resource "wiz_project" "child" {
name = "project_with_accounts"
parent_project_id = wiz_project.root.id
risk_profile {
business_impact = "MBI"
}
business_unit = "Technology"
cloud_account_link {
cloud_account_id = "477ea00a-4d4d-5bb4-9fa6-634691e68fff"
environment = "PRODUCTION"
}
}

# This resource contains multiple organization links, one with tags and another without
resource "wiz_project" "test" {
name = "Test App"
Expand Down
2 changes: 2 additions & 0 deletions internal/acceptance/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
TcJira TestCase = "JIRA"
// TcSubscriptionResourceGroups test case
TcSubscriptionResourceGroups TestCase = "SUBSCRIPTION_RESOURCE_GROUPS"
// TcProject test case
TcProject TestCase = "PROJECT"
// TcCloudConfigRule test case
TcCloudConfigRule TestCase = "CLOUD_CONFIG_RULE"
)
2 changes: 2 additions & 0 deletions internal/acceptance/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func testAccPreCheck(t *testing.T, tc TestCase) {
envVars = append(commonEnvVars, "WIZ_INTEGRATION_JIRA_URL", "WIZ_INTEGRATION_JIRA_USERNAME", "WIZ_INTEGRATION_JIRA_PASSWORD", "WIZ_INTEGRATION_JIRA_PROJECT")
case TcSubscriptionResourceGroups:
envVars = append(commonEnvVars, "WIZ_SUBSCRIPTION_ID")
case TcProject:
envVars = append(commonEnvVars, "WIZ_SUBSCRIPTION_ID")
case TcCloudConfigRule:
envVars = append(commonEnvVars, "WIZ_SUBSCRIPTION_ID")
default:
Expand Down
80 changes: 80 additions & 0 deletions internal/acceptance/resource_project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package acceptance

import (
"fmt"
"os"
"regexp"
"testing"

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

func TestAccResourceWizProject_basic(t *testing.T) {
subscriptionID := os.Getenv("WIZ_SUBSCRIPTION_ID")
rName := acctest.RandomWithPrefix(ResourcePrefix)

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, TestCase(TcProject)) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testResourceWizProjectBasic(rName, subscriptionID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"wiz_project.foo",
"name",
rName,
),
resource.TestCheckResourceAttr(
"wiz_project.foo",
"business_unit",
"Technology",
),
resource.TestMatchResourceAttr(
"wiz_project.foo",
"slug",
regexp.MustCompile(UUIDPattern),
),
resource.TestCheckResourceAttr(
"wiz_project.foo",
"archived",
"false",
),
resource.TestCheckResourceAttr(
"wiz_project.foo",
"is_folder",
"false",
),
resource.TestCheckResourceAttr(
"wiz_project.foo",
"cloud_account_link.0.cloud_account_id",
"477ea00a-4d4d-5bb4-9fa6-634691e68de7",
),
resource.TestCheckResourceAttr(
"wiz_project.foo",
"risk_profile.0.business_impact",
"MBI",
),
),
},
},
})
}

func testResourceWizProjectBasic(rName string, subscriptionID string) string {
return fmt.Sprintf(`
resource "wiz_project" "foo" {
name = "%s"
risk_profile {
business_impact = "MBI"
}
business_unit = "Technology"
cloud_account_link {
cloud_account_id = "%s"
environment = "PRODUCTION"
shared = true
}
}
`, rName, subscriptionID)
}
Loading