From f13090381e24caefabc924cf092cfc52f577420d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Mon, 22 Apr 2024 11:50:45 +0200 Subject: [PATCH] finish schema --- internal/resource/cluster_schema.go | 28 ++-- .../resource/infrastructure_stack_model.go | 22 +-- .../resource/infrastructure_stack_schema.go | 127 ++++++++++++++++++ 3 files changed, 146 insertions(+), 31 deletions(-) diff --git a/internal/resource/cluster_schema.go b/internal/resource/cluster_schema.go index dae73df..50560c1 100644 --- a/internal/resource/cluster_schema.go +++ b/internal/resource/cluster_schema.go @@ -235,19 +235,13 @@ func (r *clusterResource) schema() schema.Schema { NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "group_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "user_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, }, }, @@ -259,19 +253,13 @@ func (r *clusterResource) schema() schema.Schema { NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "group_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, "user_id": schema.StringAttribute{ - Description: "", - MarkdownDescription: "", - Optional: true, + Optional: true, }, }, }, @@ -477,8 +465,8 @@ func (r *clusterResource) kubeconfigSchema(deprecated bool) schema.SingleNestedA ElementType: types.StringType, }, "env": schema.MapAttribute{ - Description: "Defines environment variables to expose to the process.", - MarkdownDescription: "Defines environment variables to expose to the process.", + Description: "Defines environment variables to expose to the process.", + MarkdownDescription: "Defines environment variables to expose to the process.", Optional: true, ElementType: types.StringType, }, diff --git a/internal/resource/infrastructure_stack_model.go b/internal/resource/infrastructure_stack_model.go index 60a1845..8a99a2b 100644 --- a/internal/resource/infrastructure_stack_model.go +++ b/internal/resource/infrastructure_stack_model.go @@ -144,12 +144,12 @@ type InfrastructureStackPolicyBinding struct { } type InfrastructureStackJobSpec struct { - Namespace types.String `tfsdk:"namespace"` - Raw types.String `tfsdk:"raw"` - Containers []*InfrastructureStackContainerSpec `tfsdk:"containers"` - Labels types.Map `tfsdk:"labels"` - Annotations types.Map `tfsdk:"annotations"` - ServiceAccount types.String `tfsdk:"serviceAccount"` + Namespace types.String `tfsdk:"namespace"` + Raw types.String `tfsdk:"raw"` + Containers types.Set `tfsdk:"containers"` + Labels types.Map `tfsdk:"labels"` + Annotations types.Map `tfsdk:"annotations"` + ServiceAccount types.String `tfsdk:"service_account"` } func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobGateSpecFragment) { @@ -166,13 +166,13 @@ func (isjs *InfrastructureStackJobSpec) From(spec *gqlclient.JobGateSpecFragment } type InfrastructureStackContainerSpec struct { - Image types.String `tfsdk:"image"` - Args types.List `tfsdk:"args"` - Env types.Map `tfsdk:"env"` - EnvFrom []*InfrastructureStackContainerEnvFrom `tfsdk:"envFrom"` + Image types.String `tfsdk:"image"` + Args types.Set `tfsdk:"args"` + Env types.Map `tfsdk:"env"` + EnvFrom types.Set `tfsdk:"env_from"` } type InfrastructureStackContainerEnvFrom struct { Secret types.String `tfsdk:"secret"` - ConfigMap types.String `tfsdk:"configMap"` + ConfigMap types.String `tfsdk:"config_map"` } diff --git a/internal/resource/infrastructure_stack_schema.go b/internal/resource/infrastructure_stack_schema.go index a73374c..2241452 100644 --- a/internal/resource/infrastructure_stack_schema.go +++ b/internal/resource/infrastructure_stack_schema.go @@ -1,7 +1,10 @@ package resource import ( + "github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -114,6 +117,130 @@ func (r *InfrastructureStackResource) schema() schema.Schema { }, }, }, + "job_spec": schema.SingleNestedAttribute{ + Description: "Repository information used to pull stack.", + MarkdownDescription: "Repository information used to pull stack.", + Optional: true, + Attributes: map[string]schema.Attribute{ + "namespace": schema.StringAttribute{ + Description: "Namespace where job will be deployed.", + MarkdownDescription: "Namespace where job will be deployed.", + Required: true, + }, + "raw": schema.StringAttribute{ + Description: "If you'd rather define the job spec via straight Kubernetes YAML.", + MarkdownDescription: "If you'd rather define the job spec via straight Kubernetes YAML.", + Optional: true, + Validators: []validator.String{ + stringvalidator.ExactlyOneOf( + path.MatchRelative().AtParent().AtName("labels"), + path.MatchRelative().AtParent().AtName("annotations"), + path.MatchRelative().AtParent().AtName("service_account"), + path.MatchRelative().AtParent().AtName("containers"), + ), + }, + }, + "labels": schema.MapAttribute{ + Description: "Kubernetes labels applied to the job.", + MarkdownDescription: "Kubernetes labels applied to the job.", + ElementType: types.StringType, + Optional: true, + Validators: []validator.Map{mapvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName("raw"))}, + }, + "annotations": schema.MapAttribute{ + Description: "Kubernetes annotations applied to the job.", + MarkdownDescription: "Kubernetes annotations applied to the job.", + ElementType: types.StringType, + Optional: true, + Validators: []validator.Map{mapvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName("raw"))}, + }, + "service_account": schema.StringAttribute{ + Description: "Kubernetes service account for this job.", + MarkdownDescription: "Kubernetes service account for this job.", + Optional: true, + Validators: []validator.String{stringvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName("raw"))}, + }, + "containers": schema.SetNestedAttribute{ + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "image": schema.StringAttribute{ + Required: true, + }, + "args": schema.SetAttribute{ + Description: "Arguments to pass to the command when executing it.", + MarkdownDescription: "Arguments to pass to the command when executing it.", + Optional: true, + ElementType: types.StringType, + }, + "env": schema.MapAttribute{ + Description: "Defines environment variables to expose to the process.", + MarkdownDescription: "Defines environment variables to expose to the process.", + Optional: true, + ElementType: types.StringType, + }, + "env_from": schema.SetNestedAttribute{ + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "secret": schema.StringAttribute{ + Required: true, + }, + "config_map": schema.StringAttribute{ + Required: true, + }, + }, + }, + }, + }, + }, + Validators: []validator.Set{setvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName("raw"))}, + }, + }, + }, + "bindings": schema.SingleNestedAttribute{ + Description: "Read and write policies of this stack.", + MarkdownDescription: "Read and write policies of this stack.", + Optional: true, + Attributes: map[string]schema.Attribute{ + "read": schema.SetNestedAttribute{ + Description: "Read policies of this stack.", + MarkdownDescription: "Read policies of this stack.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "group_id": schema.StringAttribute{ + Optional: true, + }, + "id": schema.StringAttribute{ + Optional: true, + }, + "user_id": schema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + "write": schema.SetNestedAttribute{ + Description: "Write policies of this stack.", + MarkdownDescription: "Write policies of this stack.", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "group_id": schema.StringAttribute{ + Optional: true, + }, + "id": schema.StringAttribute{ + Optional: true, + }, + "user_id": schema.StringAttribute{ + Optional: true, + }, + }, + }, + }, + }, + }, }, } }