feat: build taint datasource and taint resource with minor patch to taint Response DTO

This commit is contained in:
allanice001
2025-11-03 01:00:35 +00:00
parent c00a0c3d1e
commit 9d60b6cbfe
21 changed files with 651 additions and 30 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -168,12 +168,18 @@ definitions:
type: object type: object
dto.TaintResponse: dto.TaintResponse:
properties: properties:
created_at:
type: string
effect: effect:
type: string type: string
id: id:
type: string type: string
key: key:
type: string type: string
organization_id:
type: string
updated_at:
type: string
value: value:
type: string type: string
type: object type: object

View File

@@ -3,10 +3,13 @@ package dto
import "github.com/google/uuid" import "github.com/google/uuid"
type TaintResponse struct { type TaintResponse struct {
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
Key string `json:"key"` OrganizationID uuid.UUID `json:"organization_id"`
Value string `json:"value"` Key string `json:"key"`
Effect string `json:"effect"` Value string `json:"value"`
Effect string `json:"effect"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
} }
type CreateTaintRequest struct { type CreateTaintRequest struct {

View File

@@ -1,5 +1,4 @@
.gitignore .gitignore
.openapi-generator-ignore
.travis.yml .travis.yml
README.md README.md
api/openapi.yaml api/openapi.yaml
@@ -91,12 +90,4 @@ model_models_user.go
model_models_user_email.go model_models_user_email.go
model_utils_error_response.go model_utils_error_response.go
response.go response.go
test/api_auth_test.go
test/api_labels_test.go
test/api_me_api_keys_test.go
test/api_me_test.go
test/api_orgs_test.go
test/api_servers_test.go
test/api_ssh_test.go
test/api_taints_test.go
utils.go utils.go

View File

@@ -1967,17 +1967,26 @@ components:
type: object type: object
dto.TaintResponse: dto.TaintResponse:
example: example:
updated_at: updated_at
effect: effect effect: effect
organization_id: organization_id
created_at: created_at
id: id id: id
value: value value: value
key: key key: key
properties: properties:
created_at:
type: string
effect: effect:
type: string type: string
id: id:
type: string type: string
key: key:
type: string type: string
organization_id:
type: string
updated_at:
type: string
value: value:
type: string type: string
type: object type: object

View File

@@ -4,9 +4,12 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**CreatedAt** | Pointer to **string** | | [optional]
**Effect** | Pointer to **string** | | [optional] **Effect** | Pointer to **string** | | [optional]
**Id** | Pointer to **string** | | [optional] **Id** | Pointer to **string** | | [optional]
**Key** | Pointer to **string** | | [optional] **Key** | Pointer to **string** | | [optional]
**OrganizationId** | Pointer to **string** | | [optional]
**UpdatedAt** | Pointer to **string** | | [optional]
**Value** | Pointer to **string** | | [optional] **Value** | Pointer to **string** | | [optional]
## Methods ## Methods
@@ -28,6 +31,31 @@ NewDtoTaintResponseWithDefaults instantiates a new DtoTaintResponse object
This constructor will only assign default values to properties that have it defined, This constructor will only assign default values to properties that have it defined,
but it doesn't guarantee that properties required by API are set but it doesn't guarantee that properties required by API are set
### GetCreatedAt
`func (o *DtoTaintResponse) GetCreatedAt() string`
GetCreatedAt returns the CreatedAt field if non-nil, zero value otherwise.
### GetCreatedAtOk
`func (o *DtoTaintResponse) GetCreatedAtOk() (*string, bool)`
GetCreatedAtOk returns a tuple with the CreatedAt field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetCreatedAt
`func (o *DtoTaintResponse) SetCreatedAt(v string)`
SetCreatedAt sets CreatedAt field to given value.
### HasCreatedAt
`func (o *DtoTaintResponse) HasCreatedAt() bool`
HasCreatedAt returns a boolean if a field has been set.
### GetEffect ### GetEffect
`func (o *DtoTaintResponse) GetEffect() string` `func (o *DtoTaintResponse) GetEffect() string`
@@ -103,6 +131,56 @@ SetKey sets Key field to given value.
HasKey returns a boolean if a field has been set. HasKey returns a boolean if a field has been set.
### GetOrganizationId
`func (o *DtoTaintResponse) GetOrganizationId() string`
GetOrganizationId returns the OrganizationId field if non-nil, zero value otherwise.
### GetOrganizationIdOk
`func (o *DtoTaintResponse) GetOrganizationIdOk() (*string, bool)`
GetOrganizationIdOk returns a tuple with the OrganizationId field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetOrganizationId
`func (o *DtoTaintResponse) SetOrganizationId(v string)`
SetOrganizationId sets OrganizationId field to given value.
### HasOrganizationId
`func (o *DtoTaintResponse) HasOrganizationId() bool`
HasOrganizationId returns a boolean if a field has been set.
### GetUpdatedAt
`func (o *DtoTaintResponse) GetUpdatedAt() string`
GetUpdatedAt returns the UpdatedAt field if non-nil, zero value otherwise.
### GetUpdatedAtOk
`func (o *DtoTaintResponse) GetUpdatedAtOk() (*string, bool)`
GetUpdatedAtOk returns a tuple with the UpdatedAt field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.
### SetUpdatedAt
`func (o *DtoTaintResponse) SetUpdatedAt(v string)`
SetUpdatedAt sets UpdatedAt field to given value.
### HasUpdatedAt
`func (o *DtoTaintResponse) HasUpdatedAt() bool`
HasUpdatedAt returns a boolean if a field has been set.
### GetValue ### GetValue
`func (o *DtoTaintResponse) GetValue() string` `func (o *DtoTaintResponse) GetValue() string`

View File

@@ -19,10 +19,13 @@ var _ MappedNullable = &DtoTaintResponse{}
// DtoTaintResponse struct for DtoTaintResponse // DtoTaintResponse struct for DtoTaintResponse
type DtoTaintResponse struct { type DtoTaintResponse struct {
Effect *string `json:"effect,omitempty"` CreatedAt *string `json:"created_at,omitempty"`
Id *string `json:"id,omitempty"` Effect *string `json:"effect,omitempty"`
Key *string `json:"key,omitempty"` Id *string `json:"id,omitempty"`
Value *string `json:"value,omitempty"` Key *string `json:"key,omitempty"`
OrganizationId *string `json:"organization_id,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
Value *string `json:"value,omitempty"`
} }
// NewDtoTaintResponse instantiates a new DtoTaintResponse object // NewDtoTaintResponse instantiates a new DtoTaintResponse object
@@ -42,6 +45,38 @@ func NewDtoTaintResponseWithDefaults() *DtoTaintResponse {
return &this return &this
} }
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *DtoTaintResponse) GetCreatedAt() string {
if o == nil || IsNil(o.CreatedAt) {
var ret string
return ret
}
return *o.CreatedAt
}
// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DtoTaintResponse) GetCreatedAtOk() (*string, bool) {
if o == nil || IsNil(o.CreatedAt) {
return nil, false
}
return o.CreatedAt, true
}
// HasCreatedAt returns a boolean if a field has been set.
func (o *DtoTaintResponse) HasCreatedAt() bool {
if o != nil && !IsNil(o.CreatedAt) {
return true
}
return false
}
// SetCreatedAt gets a reference to the given string and assigns it to the CreatedAt field.
func (o *DtoTaintResponse) SetCreatedAt(v string) {
o.CreatedAt = &v
}
// GetEffect returns the Effect field value if set, zero value otherwise. // GetEffect returns the Effect field value if set, zero value otherwise.
func (o *DtoTaintResponse) GetEffect() string { func (o *DtoTaintResponse) GetEffect() string {
if o == nil || IsNil(o.Effect) { if o == nil || IsNil(o.Effect) {
@@ -138,6 +173,70 @@ func (o *DtoTaintResponse) SetKey(v string) {
o.Key = &v o.Key = &v
} }
// GetOrganizationId returns the OrganizationId field value if set, zero value otherwise.
func (o *DtoTaintResponse) GetOrganizationId() string {
if o == nil || IsNil(o.OrganizationId) {
var ret string
return ret
}
return *o.OrganizationId
}
// GetOrganizationIdOk returns a tuple with the OrganizationId field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DtoTaintResponse) GetOrganizationIdOk() (*string, bool) {
if o == nil || IsNil(o.OrganizationId) {
return nil, false
}
return o.OrganizationId, true
}
// HasOrganizationId returns a boolean if a field has been set.
func (o *DtoTaintResponse) HasOrganizationId() bool {
if o != nil && !IsNil(o.OrganizationId) {
return true
}
return false
}
// SetOrganizationId gets a reference to the given string and assigns it to the OrganizationId field.
func (o *DtoTaintResponse) SetOrganizationId(v string) {
o.OrganizationId = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *DtoTaintResponse) GetUpdatedAt() string {
if o == nil || IsNil(o.UpdatedAt) {
var ret string
return ret
}
return *o.UpdatedAt
}
// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DtoTaintResponse) GetUpdatedAtOk() (*string, bool) {
if o == nil || IsNil(o.UpdatedAt) {
return nil, false
}
return o.UpdatedAt, true
}
// HasUpdatedAt returns a boolean if a field has been set.
func (o *DtoTaintResponse) HasUpdatedAt() bool {
if o != nil && !IsNil(o.UpdatedAt) {
return true
}
return false
}
// SetUpdatedAt gets a reference to the given string and assigns it to the UpdatedAt field.
func (o *DtoTaintResponse) SetUpdatedAt(v string) {
o.UpdatedAt = &v
}
// GetValue returns the Value field value if set, zero value otherwise. // GetValue returns the Value field value if set, zero value otherwise.
func (o *DtoTaintResponse) GetValue() string { func (o *DtoTaintResponse) GetValue() string {
if o == nil || IsNil(o.Value) { if o == nil || IsNil(o.Value) {
@@ -180,6 +279,9 @@ func (o DtoTaintResponse) MarshalJSON() ([]byte, error) {
func (o DtoTaintResponse) ToMap() (map[string]interface{}, error) { func (o DtoTaintResponse) ToMap() (map[string]interface{}, error) {
toSerialize := map[string]interface{}{} toSerialize := map[string]interface{}{}
if !IsNil(o.CreatedAt) {
toSerialize["created_at"] = o.CreatedAt
}
if !IsNil(o.Effect) { if !IsNil(o.Effect) {
toSerialize["effect"] = o.Effect toSerialize["effect"] = o.Effect
} }
@@ -189,6 +291,12 @@ func (o DtoTaintResponse) ToMap() (map[string]interface{}, error) {
if !IsNil(o.Key) { if !IsNil(o.Key) {
toSerialize["key"] = o.Key toSerialize["key"] = o.Key
} }
if !IsNil(o.OrganizationId) {
toSerialize["organization_id"] = o.OrganizationId
}
if !IsNil(o.UpdatedAt) {
toSerialize["updated_at"] = o.UpdatedAt
}
if !IsNil(o.Value) { if !IsNil(o.Value) {
toSerialize["value"] = o.Value toSerialize["value"] = o.Value
} }

View File

@@ -2,12 +2,15 @@
## Properties ## Properties
| Name | Type | | Name | Type |
| -------- | ------ | | ----------------- | ------ |
| `effect` | string | | `created_at` | string |
| `id` | string | | `effect` | string |
| `key` | string | | `id` | string |
| `value` | string | | `key` | string |
| `organization_id` | string |
| `updated_at` | string |
| `value` | string |
## Example ## Example
@@ -16,9 +19,12 @@ import type { DtoTaintResponse } from "@glueops/autoglue-sdk-go";
// TODO: Update the object below with actual values // TODO: Update the object below with actual values
const example = { const example = {
created_at: null,
effect: null, effect: null,
id: null, id: null,
key: null, key: null,
organization_id: null,
updated_at: null,
value: null, value: null,
} satisfies DtoTaintResponse; } satisfies DtoTaintResponse;

View File

@@ -19,6 +19,12 @@ import { mapValues } from "../runtime";
* @interface DtoTaintResponse * @interface DtoTaintResponse
*/ */
export interface DtoTaintResponse { export interface DtoTaintResponse {
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
created_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -37,6 +43,18 @@ export interface DtoTaintResponse {
* @memberof DtoTaintResponse * @memberof DtoTaintResponse
*/ */
key?: string; key?: string;
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
organization_id?: string;
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
updated_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -66,9 +84,13 @@ export function DtoTaintResponseFromJSONTyped(
return json; return json;
} }
return { return {
created_at: json["created_at"] == null ? undefined : json["created_at"],
effect: json["effect"] == null ? undefined : json["effect"], effect: json["effect"] == null ? undefined : json["effect"],
id: json["id"] == null ? undefined : json["id"], id: json["id"] == null ? undefined : json["id"],
key: json["key"] == null ? undefined : json["key"], key: json["key"] == null ? undefined : json["key"],
organization_id:
json["organization_id"] == null ? undefined : json["organization_id"],
updated_at: json["updated_at"] == null ? undefined : json["updated_at"],
value: json["value"] == null ? undefined : json["value"], value: json["value"] == null ? undefined : json["value"],
}; };
} }
@@ -86,9 +108,12 @@ export function DtoTaintResponseToJSONTyped(
} }
return { return {
created_at: value["created_at"],
effect: value["effect"], effect: value["effect"],
id: value["id"], id: value["id"],
key: value["key"], key: value["key"],
organization_id: value["organization_id"],
updated_at: value["updated_at"],
value: value["value"], value: value["value"],
}; };
} }

View File

@@ -3,7 +3,7 @@ module github.com/glueops/terraform-provider-gsot
go 1.25.3 go 1.25.3
require ( require (
github.com/glueops/autoglue-sdk v0.0.0-00010101000000-000000000000 github.com/glueops/autoglue-sdk-go v0.0.0-00010101000000-000000000000
github.com/hashicorp/terraform-plugin-framework v1.16.1 github.com/hashicorp/terraform-plugin-framework v1.16.1
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0 github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
) )
@@ -33,4 +33,4 @@ require (
google.golang.org/protobuf v1.36.9 // indirect google.golang.org/protobuf v1.36.9 // indirect
) )
replace github.com/glueops/autoglue-sdk => ../sdk/go replace github.com/glueops/autoglue-sdk-go => ../sdk/go

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/glueops/autoglue-sdk" "github.com/glueops/autoglue-sdk-go"
"github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/diag"
) )

View File

@@ -0,0 +1,107 @@
package provider
import (
"context"
"encoding/json"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/datasource"
dschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ datasource.DataSource = &TaintsDataSource{}
var _ datasource.DataSourceWithConfigure = &TaintsDataSource{}
type TaintsDataSource struct{ client *Client }
func NewTaintsDataSource() datasource.DataSource { return &TaintsDataSource{} }
type taintsDSModel struct {
Items []taintItem `tfsdk:"items"`
}
type taintItem struct {
ID types.String `tfsdk:"id"`
OrganizationID types.String `tfsdk:"organization_id"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Key types.String `tfsdk:"key"`
Value types.String `tfsdk:"value"`
Effect types.String `tfsdk:"effect"`
Raw types.String `tfsdk:"raw"`
}
func (d *TaintsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_taints"
}
func (d *TaintsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = dschema.Schema{
Description: "List taints for the organization (org-scoped).",
Attributes: map[string]dschema.Attribute{
"items": dschema.ListNestedAttribute{
Computed: true,
Description: "Taints returned by the API.",
NestedObject: dschema.NestedAttributeObject{
Attributes: map[string]dschema.Attribute{
"id": dschema.StringAttribute{Computed: true, Description: "Taint ID (UUID)."},
"organization_id": dschema.StringAttribute{Computed: true},
"key": dschema.StringAttribute{Computed: true},
"value": dschema.StringAttribute{Computed: true},
"effect": dschema.StringAttribute{Computed: true},
"created_at": dschema.StringAttribute{Computed: true, Description: "RFC3339, UTC."},
"updated_at": dschema.StringAttribute{Computed: true, Description: "RFC3339, UTC."},
"raw": dschema.StringAttribute{Computed: true, Description: "Full JSON for the item."},
},
},
},
},
}
}
func (d *TaintsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
d.client = req.ProviderData.(*Client)
}
func (d *TaintsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
if d.client == nil || d.client.SDK == nil {
resp.Diagnostics.AddError("Client not configured", "Provider configuration missing")
return
}
var conf taintsDSModel
resp.Diagnostics.Append(req.Config.Get(ctx, &conf)...)
if resp.Diagnostics.HasError() {
return
}
call := d.client.SDK.TaintsAPI.ListTaints(ctx)
items, httpResp, err := call.Execute()
if err != nil {
resp.Diagnostics.AddError("List taints failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
out := taintsDSModel{
Items: make([]taintItem, 0, len(items)),
}
for _, item := range items {
raw, _ := json.Marshal(item)
out.Items = append(out.Items, taintItem{
ID: types.StringPointerValue(item.Id),
OrganizationID: types.StringPointerValue(item.OrganizationId),
Key: types.StringPointerValue(item.Key),
Value: types.StringPointerValue(item.Value),
Effect: types.StringPointerValue(item.Effect),
CreatedAt: types.StringPointerValue(item.CreatedAt),
UpdatedAt: types.StringPointerValue(item.UpdatedAt),
Raw: types.StringValue(string(raw)),
})
}
resp.Diagnostics.Append(resp.State.Set(ctx, &out)...)
}

View File

@@ -49,6 +49,7 @@ func (p *AutoglueProvider) DataSources(_ context.Context) []func() datasource.Da
return []func() datasource.DataSource{ return []func() datasource.DataSource{
NewSshDataSource, NewSshDataSource,
NewServersDataSource, NewServersDataSource,
NewTaintsDataSource,
} }
} }
@@ -56,5 +57,6 @@ func (p *AutoglueProvider) Resources(_ context.Context) []func() resource.Resour
return []func() resource.Resource{ return []func() resource.Resource{
NewSshResource, NewSshResource,
NewServerResource, NewServerResource,
NewTaintResource,
} }
} }

View File

@@ -7,7 +7,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/glueops/autoglue-sdk" "github.com/glueops/autoglue-sdk-go"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource"

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/glueops/autoglue-sdk" "github.com/glueops/autoglue-sdk-go"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/path"

View File

@@ -0,0 +1,256 @@
package provider
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/glueops/autoglue-sdk-go"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ resource.Resource = &TaintResource{}
var _ resource.ResourceWithConfigure = &TaintResource{}
var _ resource.ResourceWithImportState = &TaintResource{}
type TaintResource struct{ client *Client }
func NewTaintResource() resource.Resource { return &TaintResource{} }
type taintResModel struct {
ID types.String `tfsdk:"id"`
OrganizationID types.String `tfsdk:"organization_id"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Key types.String `tfsdk:"key"`
Value types.String `tfsdk:"value"`
Effect types.String `tfsdk:"effect"`
Raw types.String `tfsdk:"raw"`
}
func (r *TaintResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_taint"
}
func (r *TaintResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = rschema.Schema{
Description: "Create and manage a taint (org-scoped).",
Attributes: map[string]rschema.Attribute{
"id": rschema.StringAttribute{
Computed: true,
Description: "Server ID (UUID).",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"organization_id": rschema.StringAttribute{Computed: true},
"created_at": rschema.StringAttribute{Computed: true},
"updated_at": rschema.StringAttribute{Computed: true},
"key": rschema.StringAttribute{
Required: true,
Description: "Key.",
},
"value": rschema.StringAttribute{
Required: true,
Description: "Value.",
},
"effect": rschema.StringAttribute{
Required: true,
Description: "Effect.",
Validators: []validator.String{
stringvalidator.OneOf("NoSchedule", "NoExecute", "PreferNoSchedule"),
},
},
"raw": rschema.StringAttribute{
Computed: true,
Description: "Full server JSON from API.",
},
},
}
}
func (r *TaintResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
r.client = req.ProviderData.(*Client)
}
func (r *TaintResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
if r.client == nil || r.client.SDK == nil {
resp.Diagnostics.AddError("Client not configured", "Provider configuration missing")
return
}
var plan taintResModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
payload := autoglue.NewDtoCreateTaintRequest()
if !plan.Key.IsNull() {
k := plan.Key.ValueString()
payload.SetKey(k)
}
if !plan.Value.IsNull() {
v := plan.Value.ValueString()
payload.SetValue(v)
}
if !plan.Effect.IsNull() {
e := plan.Effect.ValueString()
payload.SetEffect(e)
}
call := r.client.SDK.TaintsAPI.CreateTaint(ctx).Body(*payload)
out, httpResp, err := call.Execute()
if err != nil {
resp.Diagnostics.AddError("Create taint failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
raw, _ := json.Marshal(out)
var state taintResModel
r.mapRespToState(out, &state)
state.Raw = types.StringValue(string(raw))
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
func (r *TaintResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
if r.client == nil || r.client.SDK == nil {
resp.Diagnostics.AddError("Client not configured", "Provider configuration missing")
return
}
var state taintResModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
if state.ID.IsNull() || state.ID.ValueString() == "" {
// Nothing to read; treat as gone
resp.State.RemoveResource(ctx)
return
}
call := r.client.SDK.TaintsAPI.GetTaint(ctx, state.ID.ValueString())
out, httpResp, err := call.Execute()
if err != nil {
if httpResp != nil && httpResp.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("Read taint failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
raw, _ := json.Marshal(out)
r.mapRespToState(out, &state)
state.Raw = types.StringValue(string(raw))
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
func (r *TaintResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
if r.client == nil || r.client.SDK == nil {
resp.Diagnostics.AddError("Client not configured", "Provider configuration missing")
return
}
var plan taintResModel
var prior taintResModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
resp.Diagnostics.Append(req.State.Get(ctx, &prior)...)
if resp.Diagnostics.HasError() {
return
}
body := autoglue.NewDtoUpdateTaintRequest()
if !plan.Key.IsNull() {
k := plan.Key.ValueString()
body.SetKey(k)
}
if !plan.Value.IsNull() {
v := plan.Value.ValueString()
body.SetValue(v)
}
if !plan.Effect.IsNull() {
e := plan.Effect.ValueString()
body.SetEffect(e)
}
call := r.client.SDK.TaintsAPI.UpdateTaint(ctx, prior.ID.ValueString()).Body(*body)
out, httpResp, err := call.Execute()
if err != nil {
// If 404 on update, treat as gone
if httpResp != nil && httpResp.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("Update taint failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
raw, _ := json.Marshal(out)
var newState taintResModel
r.mapRespToState(out, &newState)
newState.Raw = types.StringValue(string(raw))
resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...)
}
func (r *TaintResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
if r.client == nil || r.client.SDK == nil {
resp.Diagnostics.AddError("Client not configured", "Provider configuration missing")
return
}
var state taintResModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
call := r.client.SDK.TaintsAPI.DeleteTaint(ctx, state.ID.ValueString())
_, httpResp, err := call.Execute()
if err != nil {
// If already gone, that's fine
if httpResp != nil && httpResp.StatusCode == http.StatusNotFound {
return
}
resp.Diagnostics.AddError("Delete taint failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
}
func (r *TaintResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...)
}
// --- helpers ---
func (r *TaintResource) mapRespToState(s *autoglue.DtoTaintResponse, out *taintResModel) {
out.ID = types.StringPointerValue(s.Id)
out.OrganizationID = types.StringPointerValue(s.OrganizationId)
out.Key = types.StringPointerValue(s.Key)
out.Value = types.StringPointerValue(s.Value)
out.Effect = types.StringPointerValue(s.Effect)
out.CreatedAt = types.StringPointerValue(s.CreatedAt)
out.UpdatedAt = types.StringPointerValue(s.UpdatedAt)
}

View File

@@ -6,9 +6,12 @@
Name | Type Name | Type
------------ | ------------- ------------ | -------------
`created_at` | string
`effect` | string `effect` | string
`id` | string `id` | string
`key` | string `key` | string
`organization_id` | string
`updated_at` | string
`value` | string `value` | string
## Example ## Example
@@ -18,9 +21,12 @@ import type { DtoTaintResponse } from '@glueops/autoglue-sdk-go'
// TODO: Update the object below with actual values // TODO: Update the object below with actual values
const example = { const example = {
"created_at": null,
"effect": null, "effect": null,
"id": null, "id": null,
"key": null, "key": null,
"organization_id": null,
"updated_at": null,
"value": null, "value": null,
} satisfies DtoTaintResponse } satisfies DtoTaintResponse

View File

@@ -19,6 +19,12 @@ import { mapValues } from '../runtime';
* @interface DtoTaintResponse * @interface DtoTaintResponse
*/ */
export interface DtoTaintResponse { export interface DtoTaintResponse {
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
created_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -37,6 +43,18 @@ export interface DtoTaintResponse {
* @memberof DtoTaintResponse * @memberof DtoTaintResponse
*/ */
key?: string; key?: string;
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
organization_id?: string;
/**
*
* @type {string}
* @memberof DtoTaintResponse
*/
updated_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -62,9 +80,12 @@ export function DtoTaintResponseFromJSONTyped(json: any, ignoreDiscriminator: bo
} }
return { return {
'created_at': json['created_at'] == null ? undefined : json['created_at'],
'effect': json['effect'] == null ? undefined : json['effect'], 'effect': json['effect'] == null ? undefined : json['effect'],
'id': json['id'] == null ? undefined : json['id'], 'id': json['id'] == null ? undefined : json['id'],
'key': json['key'] == null ? undefined : json['key'], 'key': json['key'] == null ? undefined : json['key'],
'organization_id': json['organization_id'] == null ? undefined : json['organization_id'],
'updated_at': json['updated_at'] == null ? undefined : json['updated_at'],
'value': json['value'] == null ? undefined : json['value'], 'value': json['value'] == null ? undefined : json['value'],
}; };
} }
@@ -80,9 +101,12 @@ export function DtoTaintResponseToJSONTyped(value?: DtoTaintResponse | null, ign
return { return {
'created_at': value['created_at'],
'effect': value['effect'], 'effect': value['effect'],
'id': value['id'], 'id': value['id'],
'key': value['key'], 'key': value['key'],
'organization_id': value['organization_id'],
'updated_at': value['updated_at'],
'value': value['value'], 'value': value['value'],
}; };
} }