diff --git a/README.md b/README.md index 1909d3d..62e6652 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ # Terraform Provider for CoderForge.org -This provider is for the CoderForge.org Cloud service \ No newline at end of file +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) \ No newline at end of file diff --git a/examples/resources/cs/main.tf b/examples/resources/cs/main.tf index dadcf7e..8b1b632 100644 --- a/examples/resources/cs/main.tf +++ b/examples/resources/cs/main.tf @@ -13,24 +13,14 @@ 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" @@ -38,6 +28,11 @@ resource "coderforge_cs" "example" { 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" diff --git a/examples/resources/ks/main.tf b/examples/resources/ks/main.tf index ddf8dea..cb1f618 100644 --- a/examples/resources/ks/main.tf +++ b/examples/resources/ks/main.tf @@ -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" diff --git a/internal/provider/cs_resource.go b/internal/provider/cs_resource.go index bb16700..c7b237f 100644 --- a/internal/provider/cs_resource.go +++ b/internal/provider/cs_resource.go @@ -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 { @@ -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, }, @@ -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, @@ -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()) @@ -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) @@ -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...) @@ -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()) @@ -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) diff --git a/internal/provider/ks_resource.go b/internal/provider/ks_resource.go index 29db190..c65562c 100644 --- a/internal/provider/ks_resource.go +++ b/internal/provider/ks_resource.go @@ -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 { @@ -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, }, @@ -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, }, diff --git a/internal/provider/models.go b/internal/provider/models.go index a1ddb0f..d615909 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -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"` @@ -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"` +} diff --git a/terraform-provider-coderforge b/terraform-provider-coderforge new file mode 100755 index 0000000..660ffb3 Binary files /dev/null and b/terraform-provider-coderforge differ