Skip to content

Commit

Permalink
feat(clouds): add initial implementation for clouds client
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
anvial committed Sep 25, 2024
1 parent 2f341fc commit e8ac402
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/juju/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ControllerConfiguration struct {
type Client struct {
Applications applicationsClient
Machines machinesClient
Clouds cloudsClient
Credentials credentialsClient
Integrations integrationsClient
Models modelsClient
Expand Down Expand Up @@ -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),
Expand Down
48 changes: 48 additions & 0 deletions internal/juju/clouds.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions internal/juju/clouds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2024 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package juju
99 changes: 99 additions & 0 deletions internal/provider/resource_kubernetes_cloud.go
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 29 in internal/provider/resource_kubernetes_cloud.go

View workflow job for this annotation

GitHub Actions / golangci-lint

field `client` is unused (unused)

// subCtx is the context created with the new tflog subsystem for applications.
subCtx context.Context

Check failure on line 32 in internal/provider/resource_kubernetes_cloud.go

View workflow job for this annotation

GitHub Actions / golangci-lint

field `subCtx` is unused (unused)
}

type kubernetesCloudResourceModel struct {

Check failure on line 35 in internal/provider/resource_kubernetes_cloud.go

View workflow job for this annotation

GitHub Actions / golangci-lint

type `kubernetesCloudResourceModel` is unused (unused)
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)
}
1 change: 1 addition & 0 deletions internal/provider/resource_kubernetes_cloud_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package provider

0 comments on commit e8ac402

Please sign in to comment.