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

Commit

Permalink
Fix org specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
DAlperin committed May 27, 2022
1 parent 294bc70 commit 1354bfa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
12 changes: 12 additions & 0 deletions graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions graphql/genqlient.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ query GetFullApp($name: String) {
network
organization {
id
slug
}
autoscaling {
preferredRegion
Expand Down Expand Up @@ -47,6 +48,7 @@ mutation CreateAppMutation($name: String, $organizationId: ID!) {
status
organization {
id
slug
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions internal/provider/app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var _ tfsdk.ResourceWithImportState = flyAppResource{}
type flyAppResourceType struct{}

type flyAppResourceData struct {
Name types.String `tfsdk:"name"`
Org types.String `tfsdk:"org"`
Name types.String `tfsdk:"name"`
Org types.String `tfsdk:"org"`
OrgId types.String `tfsdk:"orgid"`
}

func (ar flyAppResourceType) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) {
Expand All @@ -40,7 +41,12 @@ func (ar flyAppResourceType) GetSchema(context.Context) (tfsdk.Schema, diag.Diag
"org": {
Computed: true,
Optional: true,
MarkdownDescription: "Optional org ID to operate upon",
MarkdownDescription: "Optional org slug to operate upon",
Type: types.StringType,
},
"orgid": {
Computed: true,
MarkdownDescription: "readonly orgid",
Type: types.StringType,
},
},
Expand Down Expand Up @@ -82,7 +88,7 @@ func (r flyAppResource) Create(ctx context.Context, req tfsdk.CreateResourceRequ
resp.Diagnostics.AddError("Could not resolve organization", err.Error())
return
}
data.Org.Value = org.Organization.Id
data.OrgId.Value = org.Organization.Id
}

mresp, err := graphql.CreateAppMutation(context.Background(), *r.provider.client, data.Name.Value, data.Org.Value)
Expand All @@ -92,8 +98,9 @@ func (r flyAppResource) Create(ctx context.Context, req tfsdk.CreateResourceRequ
}

data = flyAppResourceData{
Org: types.String{Value: mresp.CreateApp.App.Organization.Id},
Name: types.String{Value: mresp.CreateApp.App.Name},
Org: types.String{Value: mresp.CreateApp.App.Organization.Slug},
OrgId: types.String{Value: mresp.CreateApp.App.Organization.Id},
Name: types.String{Value: mresp.CreateApp.App.Name},
}

diags = resp.State.Set(ctx, &data)
Expand Down Expand Up @@ -127,8 +134,9 @@ func (r flyAppResource) Read(ctx context.Context, req tfsdk.ReadResourceRequest,
}

data = flyAppResourceData{
Name: types.String{Value: query.App.Name},
Org: types.String{Value: query.App.Organization.Id},
Name: types.String{Value: query.App.Name},
Org: types.String{Value: query.App.Organization.Slug},
OrgId: types.String{Value: query.App.Organization.Id},
}

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

0 comments on commit 1354bfa

Please sign in to comment.