-
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
15 changed files
with
2,009 additions
and
1 deletion.
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
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,149 @@ | ||
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. | ||
|
||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
"github.com/kong/terraform-provider-konnect/v2/internal/sdk" | ||
"github.com/kong/terraform-provider-konnect/v2/internal/sdk/models/operations" | ||
) | ||
|
||
// Ensure provider defined types fully satisfy framework interfaces. | ||
var _ datasource.DataSource = &GatewayConfigStoreDataSource{} | ||
var _ datasource.DataSourceWithConfigure = &GatewayConfigStoreDataSource{} | ||
|
||
func NewGatewayConfigStoreDataSource() datasource.DataSource { | ||
return &GatewayConfigStoreDataSource{} | ||
} | ||
|
||
// GatewayConfigStoreDataSource is the data source implementation. | ||
type GatewayConfigStoreDataSource struct { | ||
client *sdk.Konnect | ||
} | ||
|
||
// GatewayConfigStoreDataSourceModel describes the data model. | ||
type GatewayConfigStoreDataSourceModel struct { | ||
ControlPlaneID types.String `tfsdk:"control_plane_id"` | ||
CreatedAt types.String `tfsdk:"created_at"` | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
UpdatedAt types.String `tfsdk:"updated_at"` | ||
} | ||
|
||
// Metadata returns the data source type name. | ||
func (r *GatewayConfigStoreDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_gateway_config_store" | ||
} | ||
|
||
// Schema defines the schema for the data source. | ||
func (r *GatewayConfigStoreDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
MarkdownDescription: "GatewayConfigStore DataSource", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"control_plane_id": schema.StringAttribute{ | ||
Required: true, | ||
Description: `The UUID of your control plane. This variable is available in the Konnect manager.`, | ||
}, | ||
"created_at": schema.StringAttribute{ | ||
Computed: true, | ||
Description: `An ISO-8601 timestamp representation of entity creation date.`, | ||
}, | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: `The Config Store ID.`, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
Description: `The name of the Config Store`, | ||
}, | ||
"updated_at": schema.StringAttribute{ | ||
Computed: true, | ||
Description: `An ISO-8601 timestamp representation of entity update date.`, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (r *GatewayConfigStoreDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
// Prevent panic if the provider has not been configured. | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*sdk.Konnect) | ||
|
||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected DataSource Configure Type", | ||
fmt.Sprintf("Expected *sdk.Konnect, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
r.client = client | ||
} | ||
|
||
func (r *GatewayConfigStoreDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var data *GatewayConfigStoreDataSourceModel | ||
var item types.Object | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &item)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ | ||
UnhandledNullAsEmpty: true, | ||
UnhandledUnknownAsEmpty: true, | ||
})...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
var controlPlaneID string | ||
controlPlaneID = data.ControlPlaneID.ValueString() | ||
|
||
var configStoreID string | ||
configStoreID = data.ID.ValueString() | ||
|
||
request := operations.GetConfigStoreRequest{ | ||
ControlPlaneID: controlPlaneID, | ||
ConfigStoreID: configStoreID, | ||
} | ||
res, err := r.client.ConfigStores.GetConfigStore(ctx, request) | ||
if err != nil { | ||
resp.Diagnostics.AddError("failure to invoke API", err.Error()) | ||
if res != nil && res.RawResponse != nil { | ||
resp.Diagnostics.AddError("unexpected http request/response", debugResponse(res.RawResponse)) | ||
} | ||
return | ||
} | ||
if res == nil { | ||
resp.Diagnostics.AddError("unexpected response from API", fmt.Sprintf("%v", res)) | ||
return | ||
} | ||
if res.StatusCode == 404 { | ||
resp.State.RemoveResource(ctx) | ||
return | ||
} | ||
if res.StatusCode != 200 { | ||
resp.Diagnostics.AddError(fmt.Sprintf("unexpected response from API. Got an unexpected response code %v", res.StatusCode), debugResponse(res.RawResponse)) | ||
return | ||
} | ||
if !(res.ConfigStore != nil) { | ||
resp.Diagnostics.AddError("unexpected response from API. Got an unexpected response body", debugResponse(res.RawResponse)) | ||
return | ||
} | ||
data.RefreshFromSharedConfigStore(res.ConfigStore) | ||
|
||
// Save updated data into Terraform state | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} |
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,26 @@ | ||
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. | ||
|
||
package provider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/kong/terraform-provider-konnect/v2/internal/sdk/models/shared" | ||
"time" | ||
) | ||
|
||
func (r *GatewayConfigStoreDataSourceModel) RefreshFromSharedConfigStore(resp *shared.ConfigStore) { | ||
if resp != nil { | ||
if resp.CreatedAt != nil { | ||
r.CreatedAt = types.StringValue(resp.CreatedAt.Format(time.RFC3339Nano)) | ||
} else { | ||
r.CreatedAt = types.StringNull() | ||
} | ||
r.ID = types.StringPointerValue(resp.ID) | ||
r.Name = types.StringPointerValue(resp.Name) | ||
if resp.UpdatedAt != nil { | ||
r.UpdatedAt = types.StringValue(resp.UpdatedAt.Format(time.RFC3339Nano)) | ||
} else { | ||
r.UpdatedAt = types.StringNull() | ||
} | ||
} | ||
} |
Oops, something went wrong.