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: pingone_application_resource #818

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
3 changes: 3 additions & 0 deletions .changelog/818.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
pingone_application_resource
```
67 changes: 67 additions & 0 deletions docs/resources/application_resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
page_title: "pingone_application_resource Resource - terraform-provider-pingone"
subcategory: "SSO"
description: |-
Resource to create and manage application resources in PingOne.
---

# pingone_application_resource (Resource)

Resource to create and manage application resources in PingOne.

## Example Usage

```terraform
resource "pingone_environment" "my_environment" {
# ...
}

resource "pingone_resource" "my_awesome_custom_resource" {
environment_id = pingone_environment.my_environment.id

name = "My awesome custom resource"
}

resource "pingone_application_resource" "my_custom_application_resource" {
environment_id = pingone_environment.my_environment.id
resource_name = pingone_resource.my_resource.name

name = "Invoices"
description = "My invoices resource application"
}
```

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

### Required

- `environment_id` (String) The ID of the environment to create the resource attribute in. Must be a valid PingOne resource ID. This field is immutable and will trigger a replace plan if changed.
- `name` (String) A string that specifies the application resource name. The value must be unique for the resource.
- `resource_name` (String) The name of the resource to should be assigned as an application resource. This field is immutable and will trigger a replace plan if changed.

### Optional

- `description` (String) A string that specifies the application resource's description.

### Read-Only

- `id` (String) The ID of this resource.
- `parent` (Attributes) A single object that describes the application resource's parent. (see [below for nested schema](#nestedatt--parent))
- `resource_id` (String) The ID of the resource that is assigned as an application resource.

<a id="nestedatt--parent"></a>
### Nested Schema for `parent`

Read-Only:

- `id` (String) A string that specifies the application resource's parent ID.
- `type` (String) The application resource's parent type. Options are `PING_ONE_RESOURCE`.

## Import

Import is supported using the following syntax, where attributes in `<>` brackets are replaced with the relevant ID. For example, `<environment_id>` should be replaced with the ID of the environment to import from.

```shell
$ terraform import pingone_application_resource.example <environment_id>/<resource_id>/<application_resource_id>
```
1 change: 1 addition & 0 deletions examples/resources/pingone_application_resource/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ terraform import pingone_application_resource.example <environment_id>/<resource_id>/<application_resource_id>
17 changes: 17 additions & 0 deletions examples/resources/pingone_application_resource/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "pingone_environment" "my_environment" {
# ...
}

resource "pingone_resource" "my_awesome_custom_resource" {
environment_id = pingone_environment.my_environment.id

name = "My awesome custom resource"
}

resource "pingone_application_resource" "my_custom_application_resource" {
environment_id = pingone_environment.my_environment.id
resource_name = pingone_resource.my_resource.name

name = "Invoices"
description = "My invoices resource application"
}
81 changes: 81 additions & 0 deletions internal/acctest/service/sso/application_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package sso

import (
"context"
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/patrickcping/pingone-go-sdk-v2/management"
"github.com/pingidentity/terraform-provider-pingone/internal/acctest"
)

func ApplicationResource_CheckDestroy(s *terraform.State) error {
var ctx = context.Background()

p1Client, err := acctest.TestClient(ctx)

if err != nil {
return err
}

apiClient := p1Client.API.ManagementAPIClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "pingone_application_resource" {
continue
}

shouldContinue, err := acctest.CheckParentEnvironmentDestroy(ctx, p1Client.API.ManagementAPIClient, rs.Primary.Attributes["environment_id"])
if err != nil {
return err
}

if shouldContinue {
continue
}

_, r, err := apiClient.ApplicationResourcesApi.ReadOneApplicationResource(ctx, rs.Primary.Attributes["environment_id"], rs.Primary.Attributes["resource_id"], rs.Primary.ID).Execute()

shouldContinue, err = acctest.CheckForResourceDestroy(r, err)
if err != nil {
return err
}

if shouldContinue {
continue
}

return fmt.Errorf("PingOne Application Resource %s still exists", rs.Primary.ID)
}

return nil
}

func ApplicationResource_GetIDs(resourceName string, environmentID, customResourceID, resourceID *string) resource.TestCheckFunc {
return func(s *terraform.State) error {

rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Resource Not found: %s", resourceName)
}

*resourceID = rs.Primary.ID
*customResourceID = rs.Primary.Attributes["resource_id"]
*environmentID = rs.Primary.Attributes["environment_id"]

return nil
}
}

func ApplicationResource_RemovalDrift_PreConfig(ctx context.Context, apiClient *management.APIClient, t *testing.T, environmentID, customResourceID, resourceID string) {
if environmentID == "" || customResourceID == "" || resourceID == "" {
t.Fatalf("One of environment ID, custom resource ID or application resource ID cannot be determined. Environment ID: %s, Resource ID: %s, Application resource ID: %s", environmentID, customResourceID, resourceID)
}

_, err := apiClient.ApplicationResourcesApi.DeleteApplicationResource(ctx, environmentID, customResourceID, resourceID).Execute()
if err != nil {
t.Fatalf("Failed to delete application resource: %v", err)
}
}
Loading