-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds tembo_instance_secrets data source
- Loading branch information
1 parent
7ff1183
commit 45a6d35
Showing
28 changed files
with
3,492 additions
and
8 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,33 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "tembo_instance_secrets Data Source - terraform-provider-tembo" | ||
subcategory: "" | ||
description: |- | ||
Data Source for Tembo Instance Secrets. | ||
--- | ||
|
||
# tembo_instance_secrets (Data Source) | ||
|
||
Data Source for Tembo Instance Secrets. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `instance_id` (String) Unique ID for the instance generated by Tembo | ||
- `org_id` (String) Unique ID for the instance generated by Tembo | ||
|
||
### Read-Only | ||
|
||
- `available_secrets` (Attributes List) (see [below for nested schema](#nestedatt--available_secrets)) | ||
|
||
<a id="nestedatt--available_secrets"></a> | ||
### Nested Schema for `available_secrets` | ||
|
||
Optional: | ||
|
||
- `name` (String) Unique ID for the instance generated by Tembo | ||
- `possible_keys` (List of String) |
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
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ go 1.20 | |
use ( | ||
. | ||
./internal/provider/temboclient | ||
) | ||
./internal/provider/tembodataclient | ||
) |
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,161 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
tembodataclient "github.com/tembo-io/terraform-provider-tembo/tembodataclient" | ||
) | ||
|
||
// Ensure the implementation satisfies the expected interfaces. | ||
var ( | ||
_ datasource.DataSource = &temboInstanceSecretsDataSource{} | ||
_ datasource.DataSourceWithConfigure = &temboInstanceSecretsDataSource{} | ||
) | ||
|
||
// NewTemboInstanceSecretsDataSource is a helper function to simplify the provider implementation. | ||
func NewTemboInstanceSecretsDataSource() datasource.DataSource { | ||
return &temboInstanceSecretsDataSource{} | ||
} | ||
|
||
// TemboInstanceSecretsDataSource is the data source implementation. | ||
type temboInstanceSecretsDataSource struct { | ||
temboInstanceSecretsConfig instanceSecretsConfig | ||
} | ||
|
||
// Tembo Cluster Configuration. | ||
type instanceSecretsConfig struct { | ||
client *tembodataclient.APIClient | ||
accessToken string | ||
} | ||
|
||
// Metadata returns the data source type name. | ||
func (d *temboInstanceSecretsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_instance_secrets" | ||
} | ||
|
||
// Schema defines the schema for the data source. | ||
func (d *temboInstanceSecretsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: "Data Source for Tembo Instance Secrets.", | ||
Attributes: map[string]schema.Attribute{ | ||
"org_id": schema.StringAttribute{ | ||
MarkdownDescription: "Unique ID for the instance generated by Tembo", | ||
Required: true, | ||
}, | ||
"instance_id": schema.StringAttribute{ | ||
MarkdownDescription: "Unique ID for the instance generated by Tembo", | ||
Required: true, | ||
}, | ||
"available_secrets": schema.ListNestedAttribute{ | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "Unique ID for the instance generated by Tembo", | ||
Optional: true, | ||
}, | ||
"possible_keys": schema.ListAttribute{ | ||
Optional: true, | ||
ElementType: types.StringType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// Configure adds the provider configured client to the data source. | ||
func (d *temboInstanceSecretsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
temboInstanceSecretsConfig, ok := req.ProviderData.(instanceSecretsConfig) | ||
|
||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Data Source Configure Type", | ||
fmt.Sprintf("Expected *instanceSecretsConfig, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.temboInstanceSecretsConfig = temboInstanceSecretsConfig | ||
} | ||
|
||
// temboInstanceSecretsDataSourceModel maps the data source schema data. | ||
type temboInstanceSecretsDataSourceModel struct { | ||
OrgId types.String `tfsdk:"org_id"` | ||
InstanceId types.String `tfsdk:"instance_id"` | ||
AvailableSecrets []availableSecret `tfsdk:"available_secrets"` | ||
} | ||
|
||
// availableSecretsModel maps instanceSecrets schema data. | ||
type availableSecret struct { | ||
// The name of an available secret | ||
Name types.String `tfsdk:"name"` | ||
// For this secret, available keys | ||
PossibleKeys []types.String `tfsdk:"possible_keys"` | ||
} | ||
|
||
// Read refreshes the Terraform state with the latest data. | ||
func (d *temboInstanceSecretsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
// Get current state | ||
var state temboInstanceSecretsDataSourceModel | ||
|
||
ctx = context.WithValue(ctx, tembodataclient.ContextAccessToken, d.temboInstanceSecretsConfig.accessToken) | ||
|
||
var orgId string | ||
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("org_id"), &orgId)...) | ||
|
||
var instanceId string | ||
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("instance_id"), &instanceId)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
tflog.Error(ctx, fmt.Sprintf("error reading terraform plan %v", resp.Diagnostics.Errors())) | ||
return | ||
} | ||
|
||
// Get refreshed Instance value from API | ||
availableSecrets, _, err := d.temboInstanceSecretsConfig.client.SecretsApi.GetSecretNamesV1(ctx, orgId, instanceId).Execute() | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"Unable to Read Tembo Instance Available Secrets", | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
if len(availableSecrets) > 0 { | ||
for _, aSecret := range availableSecrets { | ||
state.AvailableSecrets = append(state.AvailableSecrets, availableSecret{Name: types.StringValue(aSecret.Name), PossibleKeys: getPossibleKeys(aSecret.PossibleKeys)}) | ||
} | ||
} | ||
|
||
// Set refreshed state | ||
diags := resp.State.Set(ctx, &state) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
|
||
func getPossibleKeys(possibleKeys []string) []basetypes.StringValue { | ||
var localPossibleKeys []basetypes.StringValue | ||
if len(possibleKeys) > 0 { | ||
for _, possibleKey := range possibleKeys { | ||
localPossibleKeys = append(localPossibleKeys, types.StringValue(possibleKey)) | ||
} | ||
} | ||
return localPossibleKeys | ||
} |
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
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
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,24 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe | ||
*.test | ||
*.prof |
23 changes: 23 additions & 0 deletions
23
internal/provider/tembodataclient/.openapi-generator-ignore
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,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
Oops, something went wrong.