Skip to content

Commit

Permalink
finish schema
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Apr 22, 2024
1 parent b3f8556 commit f130903
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 31 deletions.
28 changes: 8 additions & 20 deletions internal/resource/cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand All @@ -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,
},
},
},
Expand Down Expand Up @@ -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,
},
Expand Down
22 changes: 11 additions & 11 deletions internal/resource/infrastructure_stack_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"`
}
127 changes: 127 additions & 0 deletions internal/resource/infrastructure_stack_schema.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
},
},
},
},
},
},
},
}
}

0 comments on commit f130903

Please sign in to comment.