feat: add labels to terraform provider

This commit is contained in:
allanice001
2025-11-03 19:07:15 +00:00
parent ee824a9c5a
commit 3ca77c097d
20 changed files with 644 additions and 13 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

@@ -86,10 +86,16 @@ definitions:
type: object type: object
dto.LabelResponse: dto.LabelResponse:
properties: properties:
created_at:
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

@@ -17,7 +17,7 @@ type NodePool struct {
Taints []Taint `gorm:"many2many:node_taints;constraint:OnDelete:CASCADE" json:"taints,omitempty"` Taints []Taint `gorm:"many2many:node_taints;constraint:OnDelete:CASCADE" json:"taints,omitempty"`
//Clusters []Cluster `gorm:"many2many:cluster_node_pools;constraint:OnDelete:CASCADE" json:"clusters,omitempty"` //Clusters []Cluster `gorm:"many2many:cluster_node_pools;constraint:OnDelete:CASCADE" json:"clusters,omitempty"`
Topology string `gorm:"not null" json:"topology,omitempty"` // stacked or external Topology string `gorm:"not null" json:"topology,omitempty"` // stacked or external
Role string `gorm:"not null" json:"role,omitempty"` // master, worker, ort etcd (etcd only if topology = external Role string `gorm:"not null" json:"role,omitempty"` // master, worker, or etcd (etcd only if topology = external
CreatedAt time.Time `gorm:"not null;default:now()" json:"created_at" format:"date-time"` CreatedAt time.Time `gorm:"not null;default:now()" json:"created_at" format:"date-time"`
UpdatedAt time.Time `gorm:"not null;default:now()" json:"updated_at" format:"date-time"` UpdatedAt time.Time `gorm:"not null;default:now()" json:"updated_at" format:"date-time"`
} }

View File

@@ -1852,14 +1852,23 @@ components:
type: object type: object
dto.LabelResponse: dto.LabelResponse:
example: example:
updated_at: updated_at
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
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,8 +4,11 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**CreatedAt** | 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
@@ -27,6 +30,31 @@ NewDtoLabelResponseWithDefaults instantiates a new DtoLabelResponse 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 *DtoLabelResponse) GetCreatedAt() string`
GetCreatedAt returns the CreatedAt field if non-nil, zero value otherwise.
### GetCreatedAtOk
`func (o *DtoLabelResponse) 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 *DtoLabelResponse) SetCreatedAt(v string)`
SetCreatedAt sets CreatedAt field to given value.
### HasCreatedAt
`func (o *DtoLabelResponse) HasCreatedAt() bool`
HasCreatedAt returns a boolean if a field has been set.
### GetId ### GetId
`func (o *DtoLabelResponse) GetId() string` `func (o *DtoLabelResponse) GetId() string`
@@ -77,6 +105,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 *DtoLabelResponse) GetOrganizationId() string`
GetOrganizationId returns the OrganizationId field if non-nil, zero value otherwise.
### GetOrganizationIdOk
`func (o *DtoLabelResponse) 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 *DtoLabelResponse) SetOrganizationId(v string)`
SetOrganizationId sets OrganizationId field to given value.
### HasOrganizationId
`func (o *DtoLabelResponse) HasOrganizationId() bool`
HasOrganizationId returns a boolean if a field has been set.
### GetUpdatedAt
`func (o *DtoLabelResponse) GetUpdatedAt() string`
GetUpdatedAt returns the UpdatedAt field if non-nil, zero value otherwise.
### GetUpdatedAtOk
`func (o *DtoLabelResponse) 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 *DtoLabelResponse) SetUpdatedAt(v string)`
SetUpdatedAt sets UpdatedAt field to given value.
### HasUpdatedAt
`func (o *DtoLabelResponse) HasUpdatedAt() bool`
HasUpdatedAt returns a boolean if a field has been set.
### GetValue ### GetValue
`func (o *DtoLabelResponse) GetValue() string` `func (o *DtoLabelResponse) GetValue() string`

View File

@@ -19,9 +19,12 @@ var _ MappedNullable = &DtoLabelResponse{}
// DtoLabelResponse struct for DtoLabelResponse // DtoLabelResponse struct for DtoLabelResponse
type DtoLabelResponse struct { type DtoLabelResponse struct {
Id *string `json:"id,omitempty"` CreatedAt *string `json:"created_at,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"`
} }
// NewDtoLabelResponse instantiates a new DtoLabelResponse object // NewDtoLabelResponse instantiates a new DtoLabelResponse object
@@ -41,6 +44,38 @@ func NewDtoLabelResponseWithDefaults() *DtoLabelResponse {
return &this return &this
} }
// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise.
func (o *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) SetCreatedAt(v string) {
o.CreatedAt = &v
}
// GetId returns the Id field value if set, zero value otherwise. // GetId returns the Id field value if set, zero value otherwise.
func (o *DtoLabelResponse) GetId() string { func (o *DtoLabelResponse) GetId() string {
if o == nil || IsNil(o.Id) { if o == nil || IsNil(o.Id) {
@@ -105,6 +140,70 @@ func (o *DtoLabelResponse) SetKey(v string) {
o.Key = &v o.Key = &v
} }
// GetOrganizationId returns the OrganizationId field value if set, zero value otherwise.
func (o *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) SetOrganizationId(v string) {
o.OrganizationId = &v
}
// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise.
func (o *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) 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 *DtoLabelResponse) GetValue() string { func (o *DtoLabelResponse) GetValue() string {
if o == nil || IsNil(o.Value) { if o == nil || IsNil(o.Value) {
@@ -147,12 +246,21 @@ func (o DtoLabelResponse) MarshalJSON() ([]byte, error) {
func (o DtoLabelResponse) ToMap() (map[string]interface{}, error) { func (o DtoLabelResponse) 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.Id) { if !IsNil(o.Id) {
toSerialize["id"] = o.Id toSerialize["id"] = o.Id
} }
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,11 +2,14 @@
## Properties ## Properties
| Name | Type | | Name | Type |
| ------- | ------ | | ----------------- | ------ |
| `id` | string | | `created_at` | string |
| `key` | string | | `id` | string |
| `value` | string | | `key` | string |
| `organization_id` | string |
| `updated_at` | string |
| `value` | string |
## Example ## Example
@@ -15,8 +18,11 @@ import type { DtoLabelResponse } 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,
id: null, id: null,
key: null, key: null,
organization_id: null,
updated_at: null,
value: null, value: null,
} satisfies DtoLabelResponse; } satisfies DtoLabelResponse;

View File

@@ -19,6 +19,12 @@ import { mapValues } from "../runtime";
* @interface DtoLabelResponse * @interface DtoLabelResponse
*/ */
export interface DtoLabelResponse { export interface DtoLabelResponse {
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
created_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -31,6 +37,18 @@ export interface DtoLabelResponse {
* @memberof DtoLabelResponse * @memberof DtoLabelResponse
*/ */
key?: string; key?: string;
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
organization_id?: string;
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
updated_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -60,8 +78,12 @@ export function DtoLabelResponseFromJSONTyped(
return json; return json;
} }
return { return {
created_at: json["created_at"] == null ? undefined : json["created_at"],
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"],
}; };
} }
@@ -79,8 +101,11 @@ export function DtoLabelResponseToJSONTyped(
} }
return { return {
created_at: value["created_at"],
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

@@ -0,0 +1,104 @@
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 = &LabelsDataSource{}
var _ datasource.DataSourceWithConfigure = &LabelsDataSource{}
type LabelsDataSource struct{ client *Client }
func NewLabelsDataSource() datasource.DataSource { return &LabelsDataSource{} }
type labelsDSModel struct {
Items []labelItem `tfsdk:"items"`
}
type labelItem 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"`
Raw types.String `tfsdk:"raw"`
}
func (d *LabelsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_labels"
}
func (d *LabelsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = dschema.Schema{
Description: "List labels for the organization (org-scoped).",
Attributes: map[string]dschema.Attribute{
"items": dschema.ListNestedAttribute{
Computed: true,
Description: "Labels 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},
"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 *LabelsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
d.client = req.ProviderData.(*Client)
}
func (d *LabelsDataSource) 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 labelsDSModel
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 labels failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
out := labelsDSModel{
Items: make([]labelItem, 0, len(items)),
}
for _, item := range items {
raw, _ := json.Marshal(item)
out.Items = append(out.Items, labelItem{
ID: types.StringPointerValue(item.Id),
OrganizationID: types.StringPointerValue(item.OrganizationId),
Key: types.StringPointerValue(item.Key),
Value: types.StringPointerValue(item.Value),
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

@@ -50,6 +50,7 @@ func (p *AutoglueProvider) DataSources(_ context.Context) []func() datasource.Da
NewSshDataSource, NewSshDataSource,
NewServersDataSource, NewServersDataSource,
NewTaintsDataSource, NewTaintsDataSource,
NewLabelsDataSource,
} }
} }
@@ -58,5 +59,6 @@ func (p *AutoglueProvider) Resources(_ context.Context) []func() resource.Resour
NewSshResource, NewSshResource,
NewServerResource, NewServerResource,
NewTaintResource, NewTaintResource,
NewLabelResource,
} }
} }

View File

@@ -0,0 +1,235 @@
package provider
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/glueops/autoglue-sdk-go"
"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/types"
)
var _ resource.Resource = &LabelResource{}
var _ resource.ResourceWithConfigure = &LabelResource{}
var _ resource.ResourceWithImportState = &LabelResource{}
type LabelResource struct{ client *Client }
func NewLabelResource() resource.Resource { return &LabelResource{} }
type labelResModel 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"`
Raw types.String `tfsdk:"raw"`
}
func (r *LabelResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_label"
}
func (r *LabelResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = rschema.Schema{
Description: "Create and manage a label (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.",
},
"raw": rschema.StringAttribute{
Computed: true,
Description: "Full server JSON from API.",
},
},
}
}
func (r *LabelResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
if req.ProviderData == nil {
return
}
r.client = req.ProviderData.(*Client)
}
func (r *LabelResource) 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 labelResModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
payload := autoglue.NewDtoCreateLabelRequest()
if !plan.Key.IsNull() {
k := plan.Key.ValueString()
payload.SetKey(k)
}
if !plan.Value.IsNull() {
v := plan.Value.ValueString()
payload.SetValue(v)
}
call := r.client.SDK.LabelsAPI.CreateLabel(ctx).Body(*payload)
out, httpResp, err := call.Execute()
if err != nil {
resp.Diagnostics.AddError("Create label failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
raw, _ := json.Marshal(out)
var state labelResModel
r.mapRespToState(out, &state)
state.Raw = types.StringValue(string(raw))
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
func (r *LabelResource) 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 labelResModel
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.LabelsAPI.GetLabel(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 label 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 *LabelResource) 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 labelResModel
var prior labelResModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
resp.Diagnostics.Append(req.State.Get(ctx, &prior)...)
if resp.Diagnostics.HasError() {
return
}
body := autoglue.NewDtoUpdateLabelRequest()
if !plan.Key.IsNull() {
k := plan.Key.ValueString()
body.SetKey(k)
}
if !plan.Value.IsNull() {
v := plan.Value.ValueString()
body.SetValue(v)
}
call := r.client.SDK.LabelsAPI.UpdateLabel(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 label failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
raw, _ := json.Marshal(out)
var newState labelResModel
r.mapRespToState(out, &newState)
newState.Raw = types.StringValue(string(raw))
resp.Diagnostics.Append(resp.State.Set(ctx, &newState)...)
}
func (r *LabelResource) 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 labelResModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
call := r.client.SDK.LabelsAPI.DeleteLabel(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 label failed", fmt.Sprintf("%v", httpErr(err, httpResp)))
return
}
}
func (r *LabelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...)
}
func (r *LabelResource) mapRespToState(s *autoglue.DtoLabelResponse, out *labelResModel) {
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.CreatedAt = types.StringPointerValue(s.CreatedAt)
out.UpdatedAt = types.StringPointerValue(s.UpdatedAt)
}

View File

@@ -19,5 +19,4 @@ ssh_keys = {
download_part = "both" download_part = "both"
download_dir = "out/clusterKey" download_dir = "out/clusterKey"
} }
} }

View File

@@ -28,3 +28,4 @@ variable "ssh_keys" {
download_dir = optional(string, "out") download_dir = optional(string, "out")
})) }))
} }

View File

@@ -0,0 +1,4 @@
resource "autoglue_taints" "this" {
key = var.key
}

View File

@@ -0,0 +1,4 @@
output "ids" {
description = "Map of taint IDs by key."
value = { for k, r in autoglue_taint.this : k => r.id }
}

View File

@@ -0,0 +1,11 @@
variable "key" {
type = string
}
variable "value" {
type = string
}
variable "effect" {
type = string
}

View File

@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.5.0"
required_providers {
autoglue = {
source = "glueops/autoglue/autoglue"
}
}
}

View File

@@ -6,8 +6,11 @@
Name | Type Name | Type
------------ | ------------- ------------ | -------------
`created_at` | string
`id` | string `id` | string
`key` | string `key` | string
`organization_id` | string
`updated_at` | string
`value` | string `value` | string
## Example ## Example
@@ -17,8 +20,11 @@ import type { DtoLabelResponse } 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,
"id": null, "id": null,
"key": null, "key": null,
"organization_id": null,
"updated_at": null,
"value": null, "value": null,
} satisfies DtoLabelResponse } satisfies DtoLabelResponse

View File

@@ -19,6 +19,12 @@ import { mapValues } from '../runtime';
* @interface DtoLabelResponse * @interface DtoLabelResponse
*/ */
export interface DtoLabelResponse { export interface DtoLabelResponse {
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
created_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -31,6 +37,18 @@ export interface DtoLabelResponse {
* @memberof DtoLabelResponse * @memberof DtoLabelResponse
*/ */
key?: string; key?: string;
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
organization_id?: string;
/**
*
* @type {string}
* @memberof DtoLabelResponse
*/
updated_at?: string;
/** /**
* *
* @type {string} * @type {string}
@@ -56,8 +74,11 @@ export function DtoLabelResponseFromJSONTyped(json: any, ignoreDiscriminator: bo
} }
return { return {
'created_at': json['created_at'] == null ? undefined : json['created_at'],
'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'],
}; };
} }
@@ -73,8 +94,11 @@ export function DtoLabelResponseToJSONTyped(value?: DtoLabelResponse | null, ign
return { return {
'created_at': value['created_at'],
'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'],
}; };
} }