Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
create app with network
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemclaren committed Sep 6, 2023
1 parent d1cd659 commit 8d05735
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions internal/provider/app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ func (r *flyAppResource) Configure(_ context.Context, req resource.ConfigureRequ
}

type flyAppResourceData struct {
Name types.String `tfsdk:"name"`
Org types.String `tfsdk:"org"`
OrgId types.String `tfsdk:"orgid"`
AppUrl types.String `tfsdk:"appurl"`
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Org types.String `tfsdk:"org"`
Network types.String `tfsdk:"network"`
OrgId types.String `tfsdk:"orgid"`
AppUrl types.String `tfsdk:"appurl"`
Id types.String `tfsdk:"id"`
}

func (r *flyAppResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand All @@ -62,6 +63,11 @@ func (r *flyAppResource) Schema(_ context.Context, _ resource.SchemaRequest, res
Optional: true,
MarkdownDescription: "Optional org slug to operate upon",
},
"network": schema.StringAttribute{
Computed: true,
Optional: true,
MarkdownDescription: "Optional custom network id for the application",
},
"orgid": schema.StringAttribute{
Computed: true,
MarkdownDescription: "readonly orgid",
Expand Down Expand Up @@ -104,18 +110,19 @@ func (r *flyAppResource) Create(ctx context.Context, req resource.CreateRequest,
}
data.OrgId = types.StringValue(org.Organization.Id)
}
mresp, err := graphql.CreateAppMutation(ctx, *r.client, data.Name.ValueString(), data.OrgId.ValueString())
mresp, err := graphql.CreateAppMutation(ctx, *r.client, data.Name.ValueString(), data.OrgId.ValueString(), data.Network.ValueString())
if err != nil {
resp.Diagnostics.AddError("Create app failed", err.Error())
return
}

data = flyAppResourceData{
Org: types.StringValue(mresp.CreateApp.App.Organization.Slug),
OrgId: types.StringValue(mresp.CreateApp.App.Organization.Id),
Name: types.StringValue(mresp.CreateApp.App.Name),
AppUrl: types.StringValue(mresp.CreateApp.App.AppUrl),
Id: types.StringValue(mresp.CreateApp.App.Id),
Org: types.StringValue(mresp.CreateApp.App.Organization.Slug),
OrgId: types.StringValue(mresp.CreateApp.App.Organization.Id),
Name: types.StringValue(mresp.CreateApp.App.Name),
Network: types.StringValue(mresp.CreateApp.App.Network),
AppUrl: types.StringValue(mresp.CreateApp.App.AppUrl),
Id: types.StringValue(mresp.CreateApp.App.Id),
}

diags = resp.State.Set(ctx, &data)
Expand Down Expand Up @@ -150,11 +157,12 @@ func (r *flyAppResource) Read(ctx context.Context, req resource.ReadRequest, res
}

data := flyAppResourceData{
Name: types.StringValue(query.App.Name),
Org: types.StringValue(query.App.Organization.Slug),
OrgId: types.StringValue(query.App.Organization.Id),
AppUrl: types.StringValue(query.App.AppUrl),
Id: types.StringValue(query.App.Id),
Name: types.StringValue(query.App.Name),
Org: types.StringValue(query.App.Organization.Slug),
Network: types.StringValue(query.App.Network),
OrgId: types.StringValue(query.App.Organization.Id),
AppUrl: types.StringValue(query.App.AppUrl),
Id: types.StringValue(query.App.Id),
}

diags = resp.State.Set(ctx, &data)
Expand Down

0 comments on commit 8d05735

Please sign in to comment.