From 085bf6244077d1e784752847c528c4df306fc9f0 Mon Sep 17 00:00:00 2001 From: Clivern Date: Sat, 25 Feb 2023 21:38:08 +0100 Subject: [PATCH] init --- examples/basics/main.tf | 16 +++++++++++++++- internal/provider/provider.go | 4 ++-- internal/provider/user_resource.go | 6 ++---- main.go | 3 +-- sdk/environment.go | 2 +- sdk/project.go | 2 +- sdk/snapshot.go | 2 +- sdk/team.go | 2 +- sdk/user.go | 2 +- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/examples/basics/main.tf b/examples/basics/main.tf index 2d9dd8e..cc18c8e 100644 --- a/examples/basics/main.tf +++ b/examples/basics/main.tf @@ -6,4 +6,18 @@ terraform { } } -provider "lynx" {} +provider "lynx" { + api_url = "http://localhost:4000/api/v1" + api_key = "bd11a454-a694-49c8-b3da-0fe6cf48a27d" +} + +resource "lynx_user" "stella" { + name = "Stella Doe" + email = "stella@example.com" + role = "regular" + password = "$87272663625" +} + +output "user_id" { + value = lynx_user.stella.id +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4dda414..bf5f947 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -6,7 +6,7 @@ package provider import ( "context" - "net/http" + "os" "github.com/clivern/terraform-provider-lynx/sdk" @@ -107,7 +107,7 @@ func (p *lynxProvider) Configure(ctx context.Context, req provider.ConfigureRequ func (p *lynxProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ - UserResource, + NewUserResource, } } diff --git a/internal/provider/user_resource.go b/internal/provider/user_resource.go index 4a856d6..29a44e4 100644 --- a/internal/provider/user_resource.go +++ b/internal/provider/user_resource.go @@ -7,7 +7,6 @@ package provider import ( "context" "fmt" - "net/http" "github.com/clivern/terraform-provider-lynx/sdk" @@ -15,7 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -31,7 +29,7 @@ func NewUserResource() resource.Resource { // UserResource defines the resource implementation. type UserResource struct { - client *http.Client + client *sdk.Client } // UserResourceModel describes the resource data model. @@ -87,7 +85,7 @@ func (r *UserResource) Configure(ctx context.Context, req resource.ConfigureRequ return } - client, ok := req.ProviderData.(*http.Client) + client, ok := req.ProviderData.(*sdk.Client) if !ok { resp.Diagnostics.AddError( diff --git a/main.go b/main.go index 1032e7b..7f7d0f1 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ package main import ( "context" "flag" - "fmt" "log" "github.com/hashicorp/terraform-plugin-framework/providerserver" @@ -47,7 +46,7 @@ func main() { Debug: debug, } - err = providerserver.Serve(context.Background(), provider.New(version), opts) + err := providerserver.Serve(context.Background(), provider.New(version), opts) if err != nil { log.Fatal(err.Error()) diff --git a/sdk/environment.go b/sdk/environment.go index 6650274..76eb20a 100644 --- a/sdk/environment.go +++ b/sdk/environment.go @@ -100,7 +100,7 @@ func (c *Client) GetEnvironment(projectId, environmentId string) (*Environment, return nil, err } - environment = Environment{} + environment := Environment{} err = json.Unmarshal(body, &environment) diff --git a/sdk/project.go b/sdk/project.go index 728d242..ce68d0c 100644 --- a/sdk/project.go +++ b/sdk/project.go @@ -102,7 +102,7 @@ func (c *Client) GetProject(projectId string) (*Project, error) { return nil, err } - project = Project{} + project := Project{} err = json.Unmarshal(body, &project) diff --git a/sdk/snapshot.go b/sdk/snapshot.go index b690948..5ec90ae 100644 --- a/sdk/snapshot.go +++ b/sdk/snapshot.go @@ -66,7 +66,7 @@ func (c *Client) GetSnapshot(snapshotId string) (*Snapshot, error) { return nil, err } - snapshot = Snapshot{} + snapshot := Snapshot{} err = json.Unmarshal(body, &snapshot) diff --git a/sdk/team.go b/sdk/team.go index 431a6ea..9035144 100644 --- a/sdk/team.go +++ b/sdk/team.go @@ -102,7 +102,7 @@ func (c *Client) GetTeam(teamId string) (*Team, error) { return nil, err } - team = Team{} + team := Team{} err = json.Unmarshal(body, &team) diff --git a/sdk/user.go b/sdk/user.go index c3efda9..57c13e1 100644 --- a/sdk/user.go +++ b/sdk/user.go @@ -102,7 +102,7 @@ func (c *Client) GetUser(userId string) (*User, error) { return nil, err } - user = User{} + user := User{} err = json.Unmarshal(body, &user)