This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
411 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "pingfederate_keypair_ssl_server_certificate Data Source - terraform-provider-pingfederate" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# pingfederate_keypair_ssl_server_certificate (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "pingfederate_keypair_ssl_server_certificate" "csr" { | ||
id = pingfederate_keypair_ssl_server.demo_generate.id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `key_pair_id` (String) ID of the key pair. | ||
|
||
### Read-Only | ||
|
||
- `certificate` (String) PEM-encoded CSR of the ssl server keypair. | ||
- `id` (String) The ID of this resource. |
3 changes: 3 additions & 0 deletions
3
examples/data-sources/pingfederate_keypair_ssl_server_certificate/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "pingfederate_keypair_ssl_server_certificate" "csr" { | ||
id = pingfederate_keypair_ssl_server.demo_generate.id | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/data-sources/pingfederate_keypair_ssl_server_certificate/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource "pingfederate_keypair_ssl_server" "demo_generate" { | ||
city = "Test" | ||
common_name = "Test" | ||
country = "GB" | ||
key_algorithm = "RSA" | ||
key_size = 2048 | ||
organization = "Test" | ||
organization_unit = "Test" | ||
state = "Test" | ||
valid_days = 365 | ||
subject_alternative_names = ["foo", "bar"] | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/framework/datasource_pingfederate_keypair_ssl_server_certificate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package framework | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/iwarapter/pingfederate-sdk-go/services/keyPairsSslServer" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
) | ||
|
||
// Ensure the implementation satisfies the expected interfaces. | ||
var ( | ||
_ datasource.DataSource = &pingfederateKeyPairSslServerCertificateDataSource{} | ||
_ datasource.DataSourceWithConfigure = &pingfederateKeyPairSslServerCertificateDataSource{} | ||
) | ||
|
||
type pingfederateKeyPairSslServerCertificateDataSource struct { | ||
client *pfClient | ||
} | ||
|
||
func NewKeyPairSslServerCertificateDataSource() datasource.DataSource { | ||
return &pingfederateKeyPairSslServerCertificateDataSource{} | ||
} | ||
|
||
func (p *pingfederateKeyPairSslServerCertificateDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_keypair_ssl_server_certificate" | ||
} | ||
|
||
func (p *pingfederateKeyPairSslServerCertificateDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
p.client = req.ProviderData.(*pfClient) | ||
} | ||
|
||
func (p *pingfederateKeyPairSslServerCertificateDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"key_pair_id": schema.StringAttribute{ | ||
Description: "ID of the key pair.", | ||
Required: true, | ||
}, | ||
"certificate": schema.StringAttribute{ | ||
Description: "PEM-encoded CSR of the ssl server keypair.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (p *pingfederateKeyPairSslServerCertificateDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
type KeyPairIdData struct { | ||
Id types.String `tfsdk:"id"` | ||
KeyPairId types.String `tfsdk:"key_pair_id"` | ||
Certificate types.String `tfsdk:"certificate"` | ||
} | ||
|
||
var data KeyPairIdData | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
|
||
cert, _, err := p.client.KeyPairsSslServer.ExportCertificateFileWithContext(ctx, &keyPairsSslServer.ExportCertificateFileInput{Id: data.KeyPairId.ValueString()}) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Unable to read keypair ssl server settings certificate", err.Error()) | ||
return | ||
} | ||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), data.KeyPairId.ValueString())...) | ||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("key_pair_id"), data.KeyPairId.ValueString())...) | ||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("certificate"), *cert)...) | ||
} |
48 changes: 48 additions & 0 deletions
48
internal/framework/datasource_pingfederate_keypair_ssl_server_certificate_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package framework | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccPingFederateKeyPairSslServerCertificateDatasource(t *testing.T) { | ||
resourceName := "data.pingfederate_keypair_ssl_server_certificate.test" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccPingFederateKeyPairSslServerCertificateDatasourceConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resourceName, "certificate"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccPingFederateKeyPairSslServerCertificateDatasourceConfig() string { | ||
return ` | ||
resource "pingfederate_keypair_ssl_server" "example" { | ||
common_name = "localhost" | ||
country = "GB" | ||
key_algorithm = "RSA" | ||
key_size = 2048 | ||
organization = "Test" | ||
valid_days = 365 | ||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
data "pingfederate_keypair_ssl_server_certificate" "test" { | ||
key_pair_id = pingfederate_keypair_ssl_server.example.id | ||
} | ||
resource "pingfederate_certificates_ca" "demo" { | ||
certificate_id = "local" | ||
file_data = base64encode(data.pingfederate_keypair_ssl_server_certificate.test.certificate) | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.