Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Apr 6, 2024
1 parent 3bd730c commit 085bf62
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 14 deletions.
16 changes: 15 additions & 1 deletion examples/basics/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
role = "regular"
password = "$87272663625"
}

output "user_id" {
value = lynx_user.stella.id
}
4 changes: 2 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package provider

import (
"context"
"net/http"
"os"

"github.com/clivern/terraform-provider-lynx/sdk"

Expand Down Expand Up @@ -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,
}
}

Expand Down
6 changes: 2 additions & 4 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/clivern/terraform-provider-lynx/sdk"

"github.com/hashicorp/terraform-plugin-framework/path"
"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"
Expand All @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"context"
"flag"
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion sdk/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c *Client) GetEnvironment(projectId, environmentId string) (*Environment,
return nil, err
}

environment = Environment{}
environment := Environment{}

err = json.Unmarshal(body, &environment)

Expand Down
2 changes: 1 addition & 1 deletion sdk/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) GetProject(projectId string) (*Project, error) {
return nil, err
}

project = Project{}
project := Project{}

err = json.Unmarshal(body, &project)

Expand Down
2 changes: 1 addition & 1 deletion sdk/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Client) GetSnapshot(snapshotId string) (*Snapshot, error) {
return nil, err
}

snapshot = Snapshot{}
snapshot := Snapshot{}

err = json.Unmarshal(body, &snapshot)

Expand Down
2 changes: 1 addition & 1 deletion sdk/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) GetTeam(teamId string) (*Team, error) {
return nil, err
}

team = Team{}
team := Team{}

err = json.Unmarshal(body, &team)

Expand Down
2 changes: 1 addition & 1 deletion sdk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) GetUser(userId string) (*User, error) {
return nil, err
}

user = User{}
user := User{}

err = json.Unmarshal(body, &user)

Expand Down

0 comments on commit 085bf62

Please sign in to comment.