Skip to content

Commit

Permalink
fix: add saml application
Browse files Browse the repository at this point in the history
fix: add saml application
  • Loading branch information
stebenz authored Jan 31, 2024
2 parents 18c045f + 49fb09f commit 91e6957
Show file tree
Hide file tree
Showing 24 changed files with 723 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/application_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
page_title: "zitadel_application_apis Data Source - terraform-provider-zitadel"
subcategory: ""
description: |-
Datasource representing an API application belonging to a project, with all configuration possibilities.
Datasource representing multiple API applications belonging to a project.
---

# zitadel_application_apis (Data Source)

Datasource representing an API application belonging to a project, with all configuration possibilities.
Datasource representing multiple API applications belonging to a project.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/application_oidcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
page_title: "zitadel_application_oidcs Data Source - terraform-provider-zitadel"
subcategory: ""
description: |-
Datasource representing an OIDC application belonging to a project, with all configuration possibilities.
Datasource representing multiple OIDC applications belonging to a project.
---

# zitadel_application_oidcs (Data Source)

Datasource representing an OIDC application belonging to a project, with all configuration possibilities.
Datasource representing multiple OIDC applications belonging to a project.

## Example Usage

Expand Down
38 changes: 38 additions & 0 deletions docs/data-sources/application_saml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
page_title: "zitadel_application_saml Data Source - terraform-provider-zitadel"
subcategory: ""
description: |-
Datasource representing a SAML application belonging to a project, with all configuration possibilities.
---

# zitadel_application_saml (Data Source)

Datasource representing a SAML application belonging to a project, with all configuration possibilities.

## Example Usage

```terraform
data "zitadel_application_saml" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
app_id = "123456789012345678"
}
```

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

### Required

- `app_id` (String) The ID of this resource.
- `project_id` (String) ID of the project

### Optional

- `org_id` (String) ID of the organization

### Read-Only

- `id` (String) The ID of this resource.
- `metadata_xml` (String) Metadata as XML file
- `name` (String) Name of the application
50 changes: 50 additions & 0 deletions docs/data-sources/application_samls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
page_title: "zitadel_application_samls Data Source - terraform-provider-zitadel"
subcategory: ""
description: |-
Datasource representing multiple SAML applications belonging to a project.
---

# zitadel_application_samls (Data Source)

Datasource representing multiple SAML applications belonging to a project.

## Example Usage

```terraform
data "zitadel_application_samls" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
name = "example-name"
name_method = "TEXT_QUERY_METHOD_CONTAINS_IGNORE_CASE"
}
data "zitadel_application_saml" "default" {
for_each = toset(data.zitadel_application_samls.default.app_ids)
id = each.value
}
output "app_saml_names" {
value = toset([
for app in data.zitadel_application_saml.default : app.name
])
}
```

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

### Required

- `name` (String) Name of the application
- `project_id` (String) ID of the project

### Optional

- `name_method` (String) Method for querying applications by name, supported values: TEXT_QUERY_METHOD_EQUALS, TEXT_QUERY_METHOD_EQUALS_IGNORE_CASE, TEXT_QUERY_METHOD_STARTS_WITH, TEXT_QUERY_METHOD_STARTS_WITH_IGNORE_CASE, TEXT_QUERY_METHOD_CONTAINS, TEXT_QUERY_METHOD_CONTAINS_IGNORE_CASE, TEXT_QUERY_METHOD_ENDS_WITH, TEXT_QUERY_METHOD_ENDS_WITH_IGNORE_CASE
- `org_id` (String) ID of the organization

### Read-Only

- `app_ids` (List of String) A set of all IDs.
- `id` (String) The ID of this resource.
45 changes: 45 additions & 0 deletions docs/resources/application_saml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
page_title: "zitadel_application_saml Resource - terraform-provider-zitadel"
subcategory: ""
description: |-
Resource representing a SAML application belonging to a project, with all configuration possibilities.
---

# zitadel_application_saml (Resource)

Resource representing a SAML application belonging to a project, with all configuration possibilities.

## Example Usage

```terraform
resource "zitadel_application_saml" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
name = "applicationapi"
metadata_xml = "<?xml version=\"1.0\"?>\n<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\"\n validUntil=\"2024-01-26T17:48:38Z\"\n cacheDuration=\"PT604800S\"\n entityID=\"http://example.com/saml/metadata\">\n <md:SPSSODescriptor AuthnRequestsSigned=\"false\" WantAssertionsSigned=\"false\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>\n <md:AssertionConsumerService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\"\n Location=\"http://example.com/saml/cas\"\n index=\"1\" />\n \n </md:SPSSODescriptor>\n</md:EntityDescriptor>"
}
```

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

### Required

- `metadata_xml` (String, Sensitive) Metadata as XML file
- `name` (String) Name of the application
- `project_id` (String) ID of the project

### Optional

- `org_id` (String) ID of the organization

### Read-Only

- `id` (String) The ID of this resource.

## Import

```terraform
# The resource can be imported using the ID format `<id:project_id[:org_id]>`, e.g.
terraform import application_saml.imported '123456789012345678:123456789012345678:123456789012345678'
```
5 changes: 5 additions & 0 deletions examples/provider/data-sources/application_saml.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "zitadel_application_saml" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
app_id = "123456789012345678"
}
17 changes: 17 additions & 0 deletions examples/provider/data-sources/application_samls.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data "zitadel_application_samls" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
name = "example-name"
name_method = "TEXT_QUERY_METHOD_CONTAINS_IGNORE_CASE"
}

data "zitadel_application_saml" "default" {
for_each = toset(data.zitadel_application_samls.default.app_ids)
id = each.value
}

output "app_saml_names" {
value = toset([
for app in data.zitadel_application_saml.default : app.name
])
}
2 changes: 2 additions & 0 deletions examples/provider/resources/application_saml-import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The resource can be imported using the ID format `<id:project_id[:org_id]>`, e.g.
terraform import application_saml.imported '123456789012345678:123456789012345678:123456789012345678'
6 changes: 6 additions & 0 deletions examples/provider/resources/application_saml.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "zitadel_application_saml" "default" {
org_id = data.zitadel_org.default.id
project_id = data.zitadel_project.default.id
name = "applicationapi"
metadata_xml = "<?xml version=\"1.0\"?>\n<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\"\n validUntil=\"2024-01-26T17:48:38Z\"\n cacheDuration=\"PT604800S\"\n entityID=\"http://example.com/saml/metadata\">\n <md:SPSSODescriptor AuthnRequestsSigned=\"false\" WantAssertionsSigned=\"false\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>\n <md:AssertionConsumerService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\"\n Location=\"http://example.com/saml/cas\"\n index=\"1\" />\n \n </md:SPSSODescriptor>\n</md:EntityDescriptor>"
}
16 changes: 16 additions & 0 deletions templates/data-sources/application_saml.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

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

{{ .Description | trimspace }}

## Example Usage

{{ tffile "examples/provider/data-sources/application_saml.tf" }}

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

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

{{ .Description | trimspace }}

## Example Usage

{{ tffile "examples/provider/data-sources/application_samls.tf" }}

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

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

{{ .Description | trimspace }}

## Example Usage

{{ tffile "examples/provider/resources/application_saml.tf" }}

{{ .SchemaMarkdown | trimspace }}

## Import

{{ tffile "examples/provider/resources/application_saml-import.sh" }}
2 changes: 1 addition & 1 deletion zitadel/application_api/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetDatasource() *schema.Resource {

func ListDatasources() *schema.Resource {
return &schema.Resource{
Description: "Datasource representing an API application belonging to a project, with all configuration possibilities.",
Description: "Datasource representing multiple API applications belonging to a project.",
Schema: map[string]*schema.Schema{
helper.OrgIDVar: helper.OrgIDDatasourceField,
appIDsVar: {
Expand Down
3 changes: 3 additions & 0 deletions zitadel/application_api/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ func list(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
}
ids := make([]string, len(resp.Result))
for i, res := range resp.Result {
if res.GetApiConfig() == nil {
continue
}
ids[i] = res.Id
}
// If the ID is blank, the datasource is deleted and not usable.
Expand Down
2 changes: 1 addition & 1 deletion zitadel/application_oidc/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func GetDatasource() *schema.Resource {

func ListDatasources() *schema.Resource {
return &schema.Resource{
Description: "Datasource representing an OIDC application belonging to a project, with all configuration possibilities.",
Description: "Datasource representing multiple OIDC applications belonging to a project.",
Schema: map[string]*schema.Schema{
helper.OrgIDVar: helper.OrgIDDatasourceField,
appIDsVar: {
Expand Down
3 changes: 3 additions & 0 deletions zitadel/application_oidc/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func list(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
}
ids := make([]string, len(resp.Result))
for i, res := range resp.Result {
if res.GetOidcConfig() == nil {
continue
}
ids[i] = res.Id
}
// If the ID is blank, the datasource is deleted and not usable.
Expand Down
25 changes: 25 additions & 0 deletions zitadel/application_saml/application_saml_test_dep/dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package application_saml_test_dep

import (
"testing"

"github.com/zitadel/zitadel-go/v2/pkg/client/zitadel/management"

"github.com/zitadel/terraform-provider-zitadel/zitadel/application_saml"
"github.com/zitadel/terraform-provider-zitadel/zitadel/helper/test_utils"
)

func Create(t *testing.T, frame *test_utils.OrgTestFrame, projectID, name string) (string, string) {
return test_utils.CreateDefaultDependency(t, "zitadel_application_saml", application_saml.AppIDVar, func() (string, error) {
app, err := frame.AddSAMLApp(frame, &management.AddSAMLAppRequest{
ProjectId: projectID,
Name: name,
Metadata: &management.AddSAMLAppRequest_MetadataXml{MetadataXml: metadata(name)},
})
return app.GetAppId(), err
})
}

func metadata(name string) []byte {
return []byte("<?xml version=\"1.0\"?>\n<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\"\n validUntil=\"2024-01-26T17:48:38Z\"\n cacheDuration=\"PT604800S\"\n entityID=\"" + name + "\">\n <md:SPSSODescriptor AuthnRequestsSigned=\"false\" WantAssertionsSigned=\"false\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>\n <md:AssertionConsumerService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\"\n Location=\"http://example.com/saml/cas\"\n index=\"1\" />\n \n </md:SPSSODescriptor>\n</md:EntityDescriptor>")
}
10 changes: 10 additions & 0 deletions zitadel/application_saml/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package application_saml

const (
AppIDVar = "app_id"
appIDsVar = "app_ids"
ProjectIDVar = "project_id"
NameVar = "name"
nameMethodVar = "name_method"
MetadataXMLVar = "metadata_xml"
)
Loading

0 comments on commit 91e6957

Please sign in to comment.