@@ -10,6 +10,8 @@ import (
1010 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1111 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1212 "github.com/hashicorp/terraform-plugin-framework/types"
13+
14+ "github.com/castai/terraform-provider-castai/castai/sdk/omni"
1315)
1416
1517var (
@@ -22,9 +24,11 @@ type omniClusterResource struct {
2224}
2325
2426type omniClusterModel struct {
25- ID types.String `tfsdk:"id"`
26- OrganizationID types.String `tfsdk:"organization_id"`
27- ClusterID types.String `tfsdk:"cluster_id"`
27+ ID types.String `tfsdk:"id"`
28+ OrganizationID types.String `tfsdk:"organization_id"`
29+ ClusterID types.String `tfsdk:"cluster_id"`
30+ OmniAgentVersion types.String `tfsdk:"omni_agent_version"`
31+ PodCIDR types.String `tfsdk:"pod_cidr"`
2832}
2933
3034func newOmniClusterResource () resource.Resource {
@@ -60,6 +64,20 @@ func (r *omniClusterResource) Schema(_ context.Context, _ resource.SchemaRequest
6064 stringplanmodifier .RequiresReplace (),
6165 },
6266 },
67+ "omni_agent_version" : schema.StringAttribute {
68+ Optional : true ,
69+ Description : "Version of the omni agent running on the cluster" ,
70+ PlanModifiers : []planmodifier.String {
71+ stringplanmodifier .RequiresReplace (),
72+ },
73+ },
74+ "pod_cidr" : schema.StringAttribute {
75+ Optional : true ,
76+ Description : "Pod CIDR of the cluster" ,
77+ PlanModifiers : []planmodifier.String {
78+ stringplanmodifier .RequiresReplace (),
79+ },
80+ },
6381 },
6482 }
6583}
@@ -89,11 +107,31 @@ func (r *omniClusterResource) Create(ctx context.Context, req resource.CreateReq
89107 return
90108 }
91109
110+ agentVersion := plan .OmniAgentVersion .ValueString ()
111+ podCIDR := plan .PodCIDR .ValueString ()
112+
113+ // Both fields must be set or both must be empty
114+ if (agentVersion == "" ) != (podCIDR == "" ) {
115+ resp .Diagnostics .AddError (
116+ "Invalid configuration" ,
117+ "all cluster status fields (omni_agent_version and pod_cidr) must be set" ,
118+ )
119+ return
120+ }
121+
122+ body := omni.RegisteredCluster {}
123+ if agentVersion != "" {
124+ body .Status = & omni.RegisteredClusterStatus {
125+ OmniAgentVersion : agentVersion ,
126+ PodCidr : podCIDR ,
127+ }
128+ }
129+
92130 client := r .client .omniAPI
93131 organizationID := plan .OrganizationID .ValueString ()
94132 clusterID := plan .ClusterID .ValueString ()
95133
96- apiResp , err := client .ClustersAPIRegisterClusterWithResponse (ctx , organizationID , clusterID )
134+ apiResp , err := client .ClustersAPIRegisterClusterWithResponse (ctx , organizationID , clusterID , body )
97135 if err != nil {
98136 resp .Diagnostics .AddError ("Failed to register omni cluster" , err .Error ())
99137 return
0 commit comments