From e8ac402be4311b9bbc8a271fcbbba03f17c480eb Mon Sep 17 00:00:00 2001 From: Vitaly Antonenko Date: Wed, 21 Aug 2024 12:38:51 +0300 Subject: [PATCH] feat(clouds): add initial implementation for clouds client - Introduced `cloudsClient` struct with methods for creating, reading, updating, and destroying clouds. - Added input and output structs for `CreateCloud`, `ReadCloud`, `UpdateCloud`, and `DestroyCloud` operations. - Integrated `cloudsClient` with `SharedClient` for shared functionality. This change sets up the basic structure for managing clouds within the Juju client. --- internal/juju/client.go | 2 + internal/juju/clouds.go | 48 +++++++++ internal/juju/clouds_test.go | 4 + .../provider/resource_kubernetes_cloud.go | 99 +++++++++++++++++++ .../resource_kubernetes_cloud_test.go | 1 + 5 files changed, 154 insertions(+) create mode 100644 internal/juju/clouds.go create mode 100644 internal/juju/clouds_test.go create mode 100644 internal/provider/resource_kubernetes_cloud.go create mode 100644 internal/provider/resource_kubernetes_cloud_test.go diff --git a/internal/juju/client.go b/internal/juju/client.go index 807559eb..bf8af75a 100644 --- a/internal/juju/client.go +++ b/internal/juju/client.go @@ -42,6 +42,7 @@ type ControllerConfiguration struct { type Client struct { Applications applicationsClient Machines machinesClient + Clouds cloudsClient Credentials credentialsClient Integrations integrationsClient Models modelsClient @@ -85,6 +86,7 @@ func NewClient(ctx context.Context, config ControllerConfiguration) (*Client, er return &Client{ Applications: *newApplicationClient(sc), + Clouds: *newCloudsClient(sc), Credentials: *newCredentialsClient(sc), Integrations: *newIntegrationsClient(sc), Machines: *newMachinesClient(sc), diff --git a/internal/juju/clouds.go b/internal/juju/clouds.go new file mode 100644 index 00000000..45b66b3d --- /dev/null +++ b/internal/juju/clouds.go @@ -0,0 +1,48 @@ +// Copyright 2024 Canonical Ltd. +// Licensed under the Apache License, Version 2.0, see LICENCE file for details. + +package juju + +type cloudsClient struct { + SharedClient +} + +type CreateCloudInput struct { +} + +type CreateCloudOutput struct { +} + +type ReadCloudInput struct { +} + +type ReadCloudOutput struct { +} + +type UpdateCloudInput struct { +} + +type DestroyCloudInput struct { +} + +func newCloudsClient(sc SharedClient) *cloudsClient { + return &cloudsClient{ + SharedClient: sc, + } +} + +func (c *cloudsClient) CreateCloud(input *CreateCloudInput) (*CreateCloudOutput, error) { + return nil, nil +} + +func (c *cloudsClient) ReadCloud(input *ReadCloudInput) (*ReadCloudOutput, error) { + return nil, nil +} + +func (c *cloudsClient) UpdateCloud(input *UpdateCloudInput) error { + return nil +} + +func (c *cloudsClient) DestroyCloud(input *DestroyCloudInput) error { + return nil +} diff --git a/internal/juju/clouds_test.go b/internal/juju/clouds_test.go new file mode 100644 index 00000000..1957d204 --- /dev/null +++ b/internal/juju/clouds_test.go @@ -0,0 +1,4 @@ +// Copyright 2024 Canonical Ltd. +// Licensed under the AGPLv3, see LICENCE file for details. + +package juju diff --git a/internal/provider/resource_kubernetes_cloud.go b/internal/provider/resource_kubernetes_cloud.go new file mode 100644 index 00000000..d0cf7d9b --- /dev/null +++ b/internal/provider/resource_kubernetes_cloud.go @@ -0,0 +1,99 @@ +// Copyright 2024 Canonical Ltd. +// Licensed under the Apache License, Version 2.0, see LICENCE file for details. + +package provider + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/path" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "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" + + "github.com/juju/terraform-provider-juju/internal/juju" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &kubernetesCloudResource{} +var _ resource.ResourceWithConfigure = &kubernetesCloudResource{} +var _ resource.ResourceWithImportState = &kubernetesCloudResource{} + +func NewKubernetesCloudResource() resource.Resource { + return &kubernetesCloudResource{} +} + +type kubernetesCloudResource struct { + client *juju.Client + + // subCtx is the context created with the new tflog subsystem for applications. + subCtx context.Context +} + +type kubernetesCloudResourceModel struct { + CloudName types.String `tfsdk:"name"` + KubeConfig types.String `tfsdk:"kubeconfig"` + ParentCloudName types.String `tfsdk:"parentcloudname"` + ParentCloudRegion types.String `tfsdk:"parentcloudregion"` +} + +func (o *kubernetesCloudResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_kubernetes_cloud" +} + +func (o *kubernetesCloudResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "A resource that represent a Juju Cloud for existing controller.", + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Description: "The name of the cloud.", + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "kubeconfig": schema.StringAttribute{ + Description: "The kubeconfig file path for the cloud.", + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parentcloudname": schema.StringAttribute{ + Description: "The parent cloud name in case adding k8s cluster from existed cloud.", + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "parentcloudregion": schema.StringAttribute{ + Description: "The parent cloud region name in case adding k8s cluster from existed cloud.", + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + }, + } +} + +func (o *kubernetesCloudResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +} + +func (o *kubernetesCloudResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { +} + +func (o *kubernetesCloudResource) Update(context.Context, resource.UpdateRequest, *resource.UpdateResponse) { +} + +func (o *kubernetesCloudResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +} + +func (o *kubernetesCloudResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +} + +func (o *kubernetesCloudResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/internal/provider/resource_kubernetes_cloud_test.go b/internal/provider/resource_kubernetes_cloud_test.go new file mode 100644 index 00000000..4f504f66 --- /dev/null +++ b/internal/provider/resource_kubernetes_cloud_test.go @@ -0,0 +1 @@ +package provider