Skip to content

Commit

Permalink
updated runtimes and services tf to work with stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorsc19 committed Nov 19, 2024
1 parent 0e094f3 commit 5165393
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
6 changes: 6 additions & 0 deletions kaleido/platform/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type RuntimeResourceModel struct {
Environment types.String `tfsdk:"environment"`
Type types.String `tfsdk:"type"`
Name types.String `tfsdk:"name"`
StackID types.String `tfsdk:"stack_id"`
ConfigJSON types.String `tfsdk:"config_json"`
LogLevel types.String `tfsdk:"log_level"`
Size types.String `tfsdk:"size"`
Expand All @@ -50,6 +51,7 @@ type RuntimeAPIModel struct {
Updated *time.Time `json:"updated,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
StackID string `json:"stackId"`
Config map[string]interface{} `json:"config"`
LogLevel string `json:"loglevel,omitempty"`
Size string `json:"size,omitempty"`
Expand Down Expand Up @@ -89,6 +91,9 @@ func (r *runtimeResource) Schema(_ context.Context, _ resource.SchemaRequest, re
"name": &schema.StringAttribute{
Required: true,
},
"stack_id": &schema.StringAttribute{
Required: true,
},
"environment": &schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Expand Down Expand Up @@ -134,6 +139,7 @@ func (data *RuntimeResourceModel) toAPI(api *RuntimeAPIModel) {
// required fields
api.Type = data.Type.ValueString()
api.Name = data.Name.ValueString()
api.StackID = data.StackID.ValueString()
// optional fields
api.Config = map[string]interface{}{}
if !data.ConfigJSON.IsNull() {
Expand Down
8 changes: 8 additions & 0 deletions kaleido/platform/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "kaleido_platform_runtime" "runtime1" {
environment = "env1"
type = "besu"
name = "runtime1"
stack_id = "stack1"
config_json = jsonencode({
"setting1": "value1"
})
Expand All @@ -47,6 +48,7 @@ resource "kaleido_platform_runtime" "runtime1" {
environment = "env1"
type = "besu"
name = "runtime1"
stack_id = "stack1"
config_json = jsonencode({
"setting1": "value1",
"setting2": "value2",
Expand All @@ -65,6 +67,7 @@ resource "kaleido_platform_runtime" "runtime1" {
environment = "env1"
type = "besu"
name = "runtime1"
stack_id = "stack1"
config_json = jsonencode({
"setting1": "value1",
"setting2": "value2",
Expand Down Expand Up @@ -109,6 +112,7 @@ func TestRuntime1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(runtime1Resource, "id"),
resource.TestCheckResourceAttr(runtime1Resource, "name", `runtime1`),
resource.TestCheckResourceAttr(runtime1Resource, "stack_id", `stack1`),
resource.TestCheckResourceAttr(runtime1Resource, "type", `besu`),
resource.TestCheckResourceAttr(runtime1Resource, "config_json", `{"setting1":"value1"}`),
resource.TestCheckResourceAttr(runtime1Resource, "log_level", `info`),
Expand All @@ -124,6 +128,7 @@ func TestRuntime1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(runtime1Resource, "id"),
resource.TestCheckResourceAttr(runtime1Resource, "name", `runtime1`),
resource.TestCheckResourceAttr(runtime1Resource, "stack_id", `stack1`),
resource.TestCheckResourceAttr(runtime1Resource, "type", `besu`),
resource.TestCheckResourceAttr(runtime1Resource, "config_json", `{"setting1":"value1","setting2":"value2"}`),
resource.TestCheckResourceAttr(runtime1Resource, "log_level", `trace`),
Expand All @@ -145,6 +150,7 @@ func TestRuntime1(t *testing.T) {
"updated": "%[3]s",
"type": "besu",
"name": "runtime1",
"stackId": "stack1",
"config": {
"setting1": "value1",
"setting2": "value2"
Expand Down Expand Up @@ -174,6 +180,7 @@ func TestRuntime1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(runtime1Resource, "id"),
resource.TestCheckResourceAttr(runtime1Resource, "name", `runtime1`),
resource.TestCheckResourceAttr(runtime1Resource, "stack_id", `stack1`),
resource.TestCheckResourceAttr(runtime1Resource, "type", `besu`),
resource.TestCheckResourceAttr(runtime1Resource, "config_json", `{"setting1":"value1","setting2":"value2"}`),
resource.TestCheckResourceAttr(runtime1Resource, "log_level", `trace`),
Expand All @@ -195,6 +202,7 @@ func TestRuntime1(t *testing.T) {
"updated": "%[3]s",
"type": "besu",
"name": "runtime1",
"stackId": "stack1",
"config": {
"setting1": "value1",
"setting2": "value2"
Expand Down
17 changes: 6 additions & 11 deletions kaleido/platform/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ import (
type ServiceResourceModel struct {
ID types.String `tfsdk:"id"`
Environment types.String `tfsdk:"environment"`
Stack types.String `tfsdk:"stack"`
Runtime types.String `tfsdk:"runtime"`
Type types.String `tfsdk:"type"`
Name types.String `tfsdk:"name"`
EnvironmentMemberID types.String `tfsdk:"environment_member_id"`
StackID types.String `tfsdk:"stack_id"`
EnvironmentMemberID types.String `tfsdk:"environment_member_id"`
ConfigJSON types.String `tfsdk:"config_json"`
Endpoints types.Map `tfsdk:"endpoints"`
Hostnames types.Map `tfsdk:"hostnames"`
Expand All @@ -53,10 +52,10 @@ type ServiceAPIModel struct {
Updated *time.Time `json:"updated,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
StackID string `json:"stackId"`
Runtime ServiceAPIRuntimeRef `json:"runtime,omitempty"`
Account string `json:"account,omitempty"`
EnvironmentMemberID string `json:"environmentMemberId,omitempty"`
StackId string `json:"stackId,omitempty"`
Deleted bool `json:"deleted,omitempty"`
Config map[string]interface{} `json:"config"`
Endpoints map[string]ServiceAPIEndpoint `json:"endpoints,omitempty"`
Expand Down Expand Up @@ -115,10 +114,6 @@ func (r *serviceResource) Schema(_ context.Context, _ resource.SchemaRequest, re
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"stack": &schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
},
"runtime": &schema.StringAttribute{
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Expand All @@ -130,10 +125,10 @@ func (r *serviceResource) Schema(_ context.Context, _ resource.SchemaRequest, re
"name": &schema.StringAttribute{
Required: true,
},
"environment_member_id": &schema.StringAttribute{
Computed: true,
},
"stack_id": &schema.StringAttribute{
Required: true,
},
"environment_member_id": &schema.StringAttribute{
Computed: true,
},
"config_json": &schema.StringAttribute{
Expand Down Expand Up @@ -233,6 +228,7 @@ func (data *ServiceResourceModel) toAPI(ctx context.Context, api *ServiceAPIMode
// required fields
api.Type = data.Type.ValueString()
api.Name = data.Name.ValueString()
api.StackID = data.StackID.ValueString()
api.Runtime.ID = data.Runtime.ValueString()
api.Config = map[string]interface{}{}
if !data.ConfigJSON.IsNull() {
Expand Down Expand Up @@ -347,7 +343,6 @@ func (data *ServiceResourceModel) toAPI(ctx context.Context, api *ServiceAPIMode
func (api *ServiceAPIModel) toData(data *ServiceResourceModel, diagnostics *diag.Diagnostics) {
data.ID = types.StringValue(api.ID)
data.EnvironmentMemberID = types.StringValue(api.EnvironmentMemberID)
data.StackID = types.StringValue(api.StackId)
endpoints := map[string]attr.Value{}
endpointAttrTypes := map[string]attr.Type{
"type": types.StringType,
Expand Down
10 changes: 5 additions & 5 deletions kaleido/platform/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
var serviceStep1 = `
resource "kaleido_platform_service" "service1" {
environment = "env1"
stack = "stack1"
runtime = "runtime1"
type = "besu"
name = "service1"
stack_id = "stack1"
config_json = jsonencode({
"setting1": "value1"
})
Expand All @@ -45,10 +45,10 @@ resource "kaleido_platform_service" "service1" {
var serviceStep2 = `
resource "kaleido_platform_service" "service1" {
environment = "env1"
stack = "stack1"
runtime = "runtime1"
type = "besu"
name = "service1"
stack_id = "stack1"
config_json = jsonencode({
"setting1": "value1",
"setting2": "value2",
Expand Down Expand Up @@ -125,6 +125,7 @@ func TestService1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(service1Resource, "id"),
resource.TestCheckResourceAttr(service1Resource, "name", `service1`),
resource.TestCheckResourceAttr(service1Resource, "stack_id", `stack1`),
resource.TestCheckResourceAttr(service1Resource, "type", `besu`),
resource.TestCheckResourceAttr(service1Resource, "config_json", `{"setting1":"value1"}`),
resource.TestCheckResourceAttr(service1Resource, "endpoints.%", `1`),
Expand All @@ -138,6 +139,7 @@ func TestService1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(service1Resource, "id"),
resource.TestCheckResourceAttr(service1Resource, "name", `service1`),
resource.TestCheckResourceAttr(service1Resource, "stack_id", `stack1`),
resource.TestCheckResourceAttr(service1Resource, "type", `besu`),
resource.TestCheckResourceAttr(service1Resource, "config_json", `{"setting1":"value1","setting2":"value2"}`),
func(s *terraform.State) error {
Expand All @@ -151,11 +153,11 @@ func TestService1(t *testing.T) {
"updated": "%[3]s",
"type": "besu",
"name": "service1",
"stackId": "stack1",
"runtime": {
"id": "runtime1"
},
"environmentMemberId": "%[4]s",
"stackId": "%[5]s",
"status": "ready",
"config": {
"setting1": "value1",
Expand Down Expand Up @@ -230,7 +232,6 @@ func TestService1(t *testing.T) {
svc.Created.UTC().Format(time.RFC3339Nano),
svc.Updated.UTC().Format(time.RFC3339Nano),
svc.EnvironmentMemberID,
svc.StackId,
))
return nil
},
Expand Down Expand Up @@ -272,7 +273,6 @@ func (mp *mockPlatform) postService(res http.ResponseWriter, req *http.Request)
svc.Created = &now
svc.Updated = &now
svc.EnvironmentMemberID = nanoid.New()
svc.StackId = nanoid.New()
svc.Status = "pending"
svc.Endpoints = map[string]ServiceAPIEndpoint{
"api": {
Expand Down

0 comments on commit 5165393

Please sign in to comment.