Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
# Terraform Provider for CoderForge.org

This provider is for the CoderForge.org Cloud service
This provider is for the CoderForge.org Cloud service

## Resources

The provider supports the following resources:

- `coderforge_function` - Deploy serverless functions
- `coderforge_container` - Deploy containerized applications
- `coderforge_container_registry` - Manage container registries
- `coderforge_ks` - Deploy Kubernetes clusters (KS)
- `coderforge_cs` - Deploy container services (CS)

## KS Resource (Simplified)

The `coderforge_ks` resource provides focused Kubernetes cluster management with core fields:

- **Core Fields**:
- `cluster_name` - Name of the Kubernetes cluster
- `version` - Kubernetes version
- `node_group_name` - Name of the node group
- `node_instance_type` - Instance type for nodes
- `node_min_size` - Minimum number of nodes
- `node_max_size` - Maximum number of nodes
- `node_desired_size` - Desired number of nodes

- **Inherited Fields** (from BaseResourceModel):
- `security_group_ids` - Security group IDs
- `logging_enabled` - Enable logging
- `log_types` - Types of logs to collect
- `tags` - Resource tags
- `last_updated` - Last update timestamp (computed)

## CS Resource (Simplified)

The `coderforge_cs` resource provides focused container service management with core fields:

- **Core Fields**:
- `service_name` - Name of the container service
- `desired_count` - Number of desired instances
- `platform_version` - Platform version for the service
- `container_port` - Port the container listens on
- `container_name` - Name of the container
- `container_image` - Docker image to use
- `container_memory` - Memory allocation for the container
- `container_cpu` - CPU allocation for the container
- `environment_variables` - Environment variables for the container

- **Inherited Fields** (from BaseResourceModel):
- `security_group_ids` - Security group IDs
- `logging_enabled` - Enable logging
- `log_types` - Types of logs to collect
- `tags` - Resource tags
- `last_updated` - Last update timestamp (computed)
31 changes: 13 additions & 18 deletions examples/resources/cs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,26 @@ provider "coderforge" {
}

resource "coderforge_cs" "example" {
cluster_name = "my-cs-cluster"
service_name = "my-cs-service"
task_definition_family = "my-task-family"
task_definition_revision = "1"
desired_count = 2
launch_type = "FARGATE"
platform_version = "LATEST"
region = "us-east-1"
vpc_id = "vpc-12345678"
subnet_ids = ["subnet-12345678", "subnet-87654321"]
security_group_ids = ["sg-12345678"]
load_balancer_arn = "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"
target_group_arn = "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
container_port = 80
container_name = "my-container"
container_image = "nginx:latest"
container_memory = 512
container_cpu = 256
service_name = "my-cs-service"
desired_count = 2
platform_version = "LATEST"
container_port = 80
container_name = "my-container"
container_image = "nginx:latest"
container_memory = 512
container_cpu = 256

environment_variables = {
NODE_ENV = "production"
PORT = "80"
LOG_LEVEL = "info"
}

# Inherited fields from BaseResourceModel
security_group_ids = ["sg-12345678"]
logging_enabled = true
log_types = ["application", "platform"]

tags = {
Environment = "development"
Project = "my-project"
Expand Down
28 changes: 12 additions & 16 deletions examples/resources/ks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ provider "coderforge" {
}

resource "coderforge_ks" "example" {
cluster_name = "my-ks-cluster"
version = "1.28"
region = "us-east-1"
node_group_name = "my-node-group"
node_instance_type = "t3.medium"
node_min_size = 1
node_max_size = 3
node_desired_size = 2
vpc_id = "vpc-12345678"
subnet_ids = ["subnet-12345678", "subnet-87654321"]
security_group_ids = ["sg-12345678"]
endpoint_private_access = true
endpoint_public_access = true
public_access_cidrs = ["0.0.0.0/0"]
logging_enabled = true
log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
cluster_name = "my-ks-cluster"
version = "1.28"
node_group_name = "my-node-group"
node_instance_type = "t3.medium"
node_min_size = 1
node_max_size = 3
node_desired_size = 2

# Inherited fields from BaseResourceModel
security_group_ids = ["sg-12345678"]
logging_enabled = true
log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]

tags = {
Environment = "development"
Expand Down
84 changes: 25 additions & 59 deletions internal/provider/cs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,17 @@ func NewCsResource() resource.Resource {
}

type csResourceModel struct {
ID types.String `tfsdk:"id"`
ClusterName types.String `tfsdk:"cluster_name"`
ServiceName types.String `tfsdk:"service_name"`
TaskDefinitionFamily types.String `tfsdk:"task_definition_family"`
TaskDefinitionRevision types.String `tfsdk:"task_definition_revision"`
DesiredCount types.Int64 `tfsdk:"desired_count"`
LaunchType types.String `tfsdk:"launch_type"`
PlatformVersion types.String `tfsdk:"platform_version"`
Region types.String `tfsdk:"region"`
VpcId types.String `tfsdk:"vpc_id"`
SubnetIds types.List `tfsdk:"subnet_ids"`
SecurityGroupIds types.List `tfsdk:"security_group_ids"`
LoadBalancerArn types.String `tfsdk:"load_balancer_arn"`
TargetGroupArn types.String `tfsdk:"target_group_arn"`
ContainerPort types.Int64 `tfsdk:"container_port"`
ContainerName types.String `tfsdk:"container_name"`
ContainerImage types.String `tfsdk:"container_image"`
ContainerMemory types.Int64 `tfsdk:"container_memory"`
ContainerCpu types.Int64 `tfsdk:"container_cpu"`
EnvironmentVariables types.Map `tfsdk:"environment_variables"`
Tags types.Map `tfsdk:"tags"`
LastUpdated types.String `tfsdk:"last_updated"`
BaseResourceModel
ID types.String `tfsdk:"id"`
ServiceName types.String `tfsdk:"service_name"`
DesiredCount types.Int64 `tfsdk:"desired_count"`
PlatformVersion types.String `tfsdk:"platform_version"`
ContainerPort types.Int64 `tfsdk:"container_port"`
ContainerName types.String `tfsdk:"container_name"`
ContainerImage types.String `tfsdk:"container_image"`
ContainerMemory types.Int64 `tfsdk:"container_memory"`
ContainerCpu types.Int64 `tfsdk:"container_cpu"`
EnvironmentVariables types.Map `tfsdk:"environment_variables"`
}

type csResource struct {
Expand All @@ -59,47 +48,15 @@ func (r *csResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
"id": schema.StringAttribute{
Computed: true,
},
"cluster_name": schema.StringAttribute{
Required: true,
},
"service_name": schema.StringAttribute{
Required: true,
},
"task_definition_family": schema.StringAttribute{
Required: true,
},
"task_definition_revision": schema.StringAttribute{
Optional: true,
},
"desired_count": schema.Int64Attribute{
Optional: true,
},
"launch_type": schema.StringAttribute{
Optional: true,
},
"platform_version": schema.StringAttribute{
Optional: true,
},
"region": schema.StringAttribute{
Required: true,
},
"vpc_id": schema.StringAttribute{
Optional: true,
},
"subnet_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"security_group_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"load_balancer_arn": schema.StringAttribute{
Optional: true,
},
"target_group_arn": schema.StringAttribute{
Optional: true,
},
"container_port": schema.Int64Attribute{
Optional: true,
},
Expand All @@ -119,6 +76,18 @@ func (r *csResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
ElementType: types.StringType,
Optional: true,
},
// Inherited fields from BaseResourceModel
"security_group_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"logging_enabled": schema.BoolAttribute{
Optional: true,
},
"log_types": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"tags": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
Expand Down Expand Up @@ -149,7 +118,7 @@ func (r *csResource) Create(ctx context.Context, req resource.CreateRequest, res
code := Code{
PackageType: "container",
ImageUri: plan.ContainerImage.ValueString(),
Runtime: plan.LaunchType.ValueString(),
Runtime: "container",
}
resourceItem.Code = code
resourceItem.MaxRamSize = fmt.Sprintf("%d", plan.ContainerMemory.ValueInt64())
Expand All @@ -167,7 +136,6 @@ func (r *csResource) Create(ctx context.Context, req resource.CreateRequest, res
plan.ID = types.StringValue(resourceItemRes.ID)
plan.ServiceName = types.StringValue(resourceItemRes.Name)
plan.ContainerImage = types.StringValue(resourceItemRes.Code.ImageUri)
plan.LaunchType = types.StringValue(resourceItemRes.Code.Runtime)
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))

diags = resp.State.Set(ctx, plan)
Expand Down Expand Up @@ -206,7 +174,6 @@ func (r *csResource) Read(ctx context.Context, req resource.ReadRequest, resp *r
state.ID = types.StringValue(resourceItemRes.ID)
state.ServiceName = types.StringValue(resourceItemRes.Name)
state.ContainerImage = types.StringValue(resourceItemRes.Code.ImageUri)
state.LaunchType = types.StringValue(resourceItemRes.Code.Runtime)

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -234,7 +201,7 @@ func (r *csResource) Update(ctx context.Context, req resource.UpdateRequest, res
code := Code{
PackageType: "container",
ImageUri: plan.ContainerImage.ValueString(),
Runtime: plan.LaunchType.ValueString(),
Runtime: "container",
}
resourceItem.Code = code
resourceItem.MaxRamSize = fmt.Sprintf("%d", plan.ContainerMemory.ValueInt64())
Expand All @@ -251,7 +218,6 @@ func (r *csResource) Update(ctx context.Context, req resource.UpdateRequest, res
plan.ID = types.StringValue(resourceItemRes.ID)
plan.ServiceName = types.StringValue(resourceItemRes.Name)
plan.ContainerImage = types.StringValue(resourceItemRes.Code.ImageUri)
plan.LaunchType = types.StringValue(resourceItemRes.Code.Runtime)
plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))

diags = resp.State.Set(ctx, plan)
Expand Down
49 changes: 10 additions & 39 deletions internal/provider/ks_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,15 @@ func NewKsResource() resource.Resource {
}

type ksResourceModel struct {
ID types.String `tfsdk:"id"`
ClusterName types.String `tfsdk:"cluster_name"`
Version types.String `tfsdk:"version"`
Region types.String `tfsdk:"region"`
NodeGroupName types.String `tfsdk:"node_group_name"`
NodeInstanceType types.String `tfsdk:"node_instance_type"`
NodeMinSize types.Int64 `tfsdk:"node_min_size"`
NodeMaxSize types.Int64 `tfsdk:"node_max_size"`
NodeDesiredSize types.Int64 `tfsdk:"node_desired_size"`
VpcId types.String `tfsdk:"vpc_id"`
SubnetIds types.List `tfsdk:"subnet_ids"`
SecurityGroupIds types.List `tfsdk:"security_group_ids"`
EndpointPrivateAccess types.Bool `tfsdk:"endpoint_private_access"`
EndpointPublicAccess types.Bool `tfsdk:"endpoint_public_access"`
PublicAccessCidrs types.List `tfsdk:"public_access_cidrs"`
LoggingEnabled types.Bool `tfsdk:"logging_enabled"`
LogTypes types.List `tfsdk:"log_types"`
Tags types.Map `tfsdk:"tags"`
LastUpdated types.String `tfsdk:"last_updated"`
BaseResourceModel
ID types.String `tfsdk:"id"`
ClusterName types.String `tfsdk:"cluster_name"`
Version types.String `tfsdk:"version"`
NodeGroupName types.String `tfsdk:"node_group_name"`
NodeInstanceType types.String `tfsdk:"node_instance_type"`
NodeMinSize types.Int64 `tfsdk:"node_min_size"`
NodeMaxSize types.Int64 `tfsdk:"node_max_size"`
NodeDesiredSize types.Int64 `tfsdk:"node_desired_size"`
}

type ksResource struct {
Expand All @@ -62,9 +52,6 @@ func (r *ksResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
"version": schema.StringAttribute{
Optional: true,
},
"region": schema.StringAttribute{
Required: true,
},
"node_group_name": schema.StringAttribute{
Optional: true,
},
Expand All @@ -80,27 +67,11 @@ func (r *ksResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *r
"node_desired_size": schema.Int64Attribute{
Optional: true,
},
"vpc_id": schema.StringAttribute{
Optional: true,
},
"subnet_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
// Inherited fields from BaseResourceModel
"security_group_ids": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"endpoint_private_access": schema.BoolAttribute{
Optional: true,
},
"endpoint_public_access": schema.BoolAttribute{
Optional: true,
},
"public_access_cidrs": schema.ListAttribute{
ElementType: types.StringType,
Optional: true,
},
"logging_enabled": schema.BoolAttribute{
Optional: true,
},
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package provider

import "github.com/hashicorp/terraform-plugin-framework/types"

type CloudData struct {
StackId string `json:"stackId"`
CloudSpace string `json:"cloudSpace"`
Expand Down Expand Up @@ -37,3 +39,12 @@ type DataItem struct {
type LogoutStruct struct {
IdTokenHint string `json:"id_token_hint"`
}

// BaseResourceModel contains common fields that all resources inherit
type BaseResourceModel struct {
SecurityGroupIds types.List `tfsdk:"security_group_ids"`
LoggingEnabled types.Bool `tfsdk:"logging_enabled"`
LogTypes types.List `tfsdk:"log_types"`
Tags types.Map `tfsdk:"tags"`
LastUpdated types.String `tfsdk:"last_updated"`
}
Binary file added terraform-provider-coderforge
Binary file not shown.