Skip to content

Commit

Permalink
Replace stack network type with network ID
Browse files Browse the repository at this point in the history
  • Loading branch information
lanasta committed Dec 6, 2024
1 parent d9304c5 commit 9cfe4d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
19 changes: 9 additions & 10 deletions kaleido/platform/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type StacksResourceModel struct {
EnvironmentMemberID types.String `tfsdk:"environment_member_id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
NetworkType types.String `tfsdk:"network_type"`
NetworkId types.String `tfsdk:"network_id"`
}

type StacksAPIModel struct {
Expand All @@ -44,7 +44,7 @@ type StacksAPIModel struct {
EnvironmentMemberID string `json:"environmentMemberId,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
NetworkType string `json:"networkType,omitempty"`
NetworkId string `json:"networkId"`
}

func StacksResourceFactory() resource.Resource {
Expand Down Expand Up @@ -80,9 +80,8 @@ func (r *stacksResource) Schema(_ context.Context, _ resource.SchemaRequest, res
"environment_member_id": &schema.StringAttribute{
Computed: true,
},
"network_type": &schema.StringAttribute{
Optional: true,
Computed: true,
"network_id": &schema.StringAttribute{
Required: true,
},
},
}
Expand All @@ -91,19 +90,19 @@ func (r *stacksResource) Schema(_ context.Context, _ resource.SchemaRequest, res
func (data *StacksResourceModel) toAPI(api *StacksAPIModel) {
api.Type = data.Type.ValueString()
api.Name = data.Name.ValueString()
if !data.NetworkType.IsNull() {
api.NetworkType = data.NetworkType.ValueString()
if !data.NetworkId.IsNull() {
api.NetworkId = data.NetworkId.ValueString()
}
}

func (api *StacksAPIModel) toData(data *StacksResourceModel) {
data.ID = types.StringValue(api.ID)
data.EnvironmentMemberID = types.StringValue(api.EnvironmentMemberID)
data.NetworkType = types.StringValue(api.NetworkType)
data.NetworkId = types.StringValue(api.NetworkId)
data.Name = types.StringValue(api.Name)
data.Type = types.StringValue(api.Type)
if api.NetworkType != "" && !data.NetworkType.IsNull() {
data.NetworkType = types.StringValue(api.NetworkType)
if api.NetworkId != "" && !data.NetworkId.IsNull() {
data.NetworkId = types.StringValue(api.NetworkId)
}
}

Expand Down
13 changes: 5 additions & 8 deletions kaleido/platform/stacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "kaleido_platform_stack" "stack1" {
name = "stack1"
type = "chain_infrastructure"
environment = "env1"
network_type = "BesuNetwork"
network_id = "network123"
}
`

Expand All @@ -42,7 +42,7 @@ resource "kaleido_platform_stack" "stack1" {
name = "stack1_renamed"
type = "chain_infrastructure"
environment = "env1"
network_type = "BesuNetwork"
network_id = "network123"
}
`

Expand Down Expand Up @@ -73,7 +73,7 @@ func TestStacks1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(Stack1Resource, "id"),
resource.TestCheckResourceAttr(Stack1Resource, "name", `stack1`),
resource.TestCheckResourceAttr(Stack1Resource, "network_type", `BesuNetwork`),
resource.TestCheckResourceAttr(Stack1Resource, "network_id", `network123`),
resource.TestCheckResourceAttr(Stack1Resource, "type", `chain_infrastructure`),
),
},
Expand All @@ -82,7 +82,7 @@ func TestStacks1(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(Stack1Resource, "id"),
resource.TestCheckResourceAttr(Stack1Resource, "name", `stack1_renamed`),
resource.TestCheckResourceAttr(Stack1Resource, "network_type", `BesuNetwork`),
resource.TestCheckResourceAttr(Stack1Resource, "network_id", `network123`),
resource.TestCheckResourceAttr(Stack1Resource, "type", `chain_infrastructure`),
func(s *terraform.State) error {
// Compare the final result on the mock-server side
Expand All @@ -95,7 +95,7 @@ func TestStacks1(t *testing.T) {
"updated": "%[3]s",
"type": "chain_infrastructure",
"name": "stack1_renamed",
"networkType": "BesuNetwork",
"networkId": "network123",
"environmentMemberId": "%[4]s"
}
`,
Expand Down Expand Up @@ -130,9 +130,6 @@ func (mp *mockPlatform) postStacks(res http.ResponseWriter, req *http.Request) {
rt.Created = &now
rt.Updated = &now
rt.EnvironmentMemberID = nanoid.New()
if rt.NetworkType == "" {
rt.NetworkType = "BesuNetwork"
}
mp.stacks[mux.Vars(req)["env"]+"/"+rt.ID] = &rt
mp.respond(res, &rt, 201)
}
Expand Down

0 comments on commit 9cfe4d4

Please sign in to comment.