From 0d64c53d3b5ba5c2fea1c88d01910d64a32fa525 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Thu, 4 Apr 2024 16:06:45 +0700 Subject: [PATCH] Update uplink to output installation_id --- docs/resources/uplink.md | 3 ++- .../resources/instellar_uplink/resource.tf | 2 +- instellar/uplink/resource.go | 20 +++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/resources/uplink.md b/docs/resources/uplink.md index 3adff30..52ba54b 100644 --- a/docs/resources/uplink.md +++ b/docs/resources/uplink.md @@ -23,8 +23,8 @@ resource "instellar_cluster" "main" { resource "instellar_uplink" "this" { channel_slug = "master" + kit_slug = "lite" cluster_id = instellar_cluster.main.id - database_url = "postgresql://user:pass@localhost:5432/some_db_example" } ``` @@ -41,4 +41,5 @@ resource "instellar_uplink" "this" { - `current_state` (String) The current state of uplink - `id` (String) Uplink identifier +- `installation_id` (String) Which installation does uplink belong to - `last_updated` (String) Timestamp of terraform update diff --git a/examples/resources/instellar_uplink/resource.tf b/examples/resources/instellar_uplink/resource.tf index 6bbc97e..6af2aef 100644 --- a/examples/resources/instellar_uplink/resource.tf +++ b/examples/resources/instellar_uplink/resource.tf @@ -8,6 +8,6 @@ resource "instellar_cluster" "main" { resource "instellar_uplink" "this" { channel_slug = "master" + kit_slug = "lite" cluster_id = instellar_cluster.main.id - database_url = "postgresql://user:pass@localhost:5432/some_db_example" } \ No newline at end of file diff --git a/instellar/uplink/resource.go b/instellar/uplink/resource.go index 636b651..eb7fed2 100644 --- a/instellar/uplink/resource.go +++ b/instellar/uplink/resource.go @@ -31,12 +31,13 @@ type uplinkResource struct { } type uplinkResourceModel struct { - ID types.String `tfsdk:"id"` - ChannelSlug types.String `tfsdk:"channel_slug"` - KitSlug types.String `tfsdk:"kit_slug"` - CurrentState types.String `tfsdk:"current_state"` - ClusterID types.String `tfsdk:"cluster_id"` - LastUpdated types.String `tfsdk:"last_updated"` + ID types.String `tfsdk:"id"` + ChannelSlug types.String `tfsdk:"channel_slug"` + KitSlug types.String `tfsdk:"kit_slug"` + CurrentState types.String `tfsdk:"current_state"` + ClusterID types.String `tfsdk:"cluster_id"` + InstallationID types.String `tfsdk:"installation_id"` + LastUpdated types.String `tfsdk:"last_updated"` } func (r *uplinkResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -70,6 +71,10 @@ func (r *uplinkResource) Schema(_ context.Context, _ resource.SchemaRequest, res Description: "Which cluster does uplink belong to", Required: true, }, + "installation_id": schema.StringAttribute{ + Description: "Which installation does uplink belong to", + Computed: true, + }, "last_updated": schema.StringAttribute{ Description: "Timestamp of terraform update", Computed: true, @@ -127,6 +132,7 @@ func (r *uplinkResource) Create(ctx context.Context, req resource.CreateRequest, plan.ID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.ID)) plan.CurrentState = types.StringValue(uplink.Data.Attributes.CurrentState) plan.ClusterID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.ClusterID)) + plan.InstallationID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.InstallationID)) plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) diags = resp.State.Set(ctx, plan) @@ -158,6 +164,7 @@ func (r *uplinkResource) Read(ctx context.Context, req resource.ReadRequest, res state.KitSlug = types.StringValue(uplink.Data.Attributes.KitSlug) state.CurrentState = types.StringValue(uplink.Data.Attributes.CurrentState) state.ClusterID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.ClusterID)) + state.InstallationID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.InstallationID)) diags = resp.State.Set(ctx, &state) resp.Diagnostics.Append(diags...) @@ -201,6 +208,7 @@ func (r *uplinkResource) Update(ctx context.Context, req resource.UpdateRequest, plan.ChannelSlug = types.StringValue(uplink.Data.Attributes.ChannelSlug) plan.KitSlug = types.StringValue(uplink.Data.Attributes.KitSlug) plan.CurrentState = types.StringValue(uplink.Data.Attributes.CurrentState) + plan.InstallationID = types.StringValue(strconv.Itoa(uplink.Data.Attributes.InstallationID)) plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850)) diags = resp.State.Set(ctx, plan)