Added go backend for testing purposes
This commit is contained in:
parent
eb70c87759
commit
f067936f25
4 changed files with 68 additions and 14 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
.terraform.lock.hcl
|
||||
.terraform/
|
||||
*.tfstate
|
||||
receita-provider
|
||||
backend
|
||||
|
|
41
api/backend.go
Normal file
41
api/backend.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func handleCreate(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("got /create request\n")
|
||||
io.WriteString(w, "Resource created!\n")
|
||||
}
|
||||
|
||||
func handleUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("got /update request\n")
|
||||
io.WriteString(w, "Resource updated!\n")
|
||||
}
|
||||
|
||||
func handleDelete(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("got /delete request\n")
|
||||
io.WriteString(w, "Resource deleted\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/create", handleCreate)
|
||||
mux.HandleFunc("/update", handleUpdate)
|
||||
mux.HandleFunc("/delete", handleDelete)
|
||||
|
||||
err := http.ListenAndServe(":9999", mux)
|
||||
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
fmt.Printf("server closed\n")
|
||||
} else if err != nil {
|
||||
fmt.Printf("error starting server: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
|
@ -11,6 +11,12 @@ provider "receita" {
|
|||
}
|
||||
|
||||
resource "receita_receita" "receita_one" {
|
||||
name = "Bola de carne"
|
||||
name = "Bola de carne"
|
||||
#name = "Batata frita"
|
||||
author = "Maria Bacalhau"
|
||||
}
|
||||
|
||||
resource "receita_receita" "receita_two" {
|
||||
name = "Bacalhau com Todos"
|
||||
author = "Antonio Mariscada"
|
||||
}
|
||||
|
|
|
@ -107,20 +107,11 @@ func (r *ReceitaResource) Create(ctx context.Context, req resource.CreateRequest
|
|||
|
||||
// Do specific stuff
|
||||
endpoint := r.providerData.Model.Endpoint
|
||||
hResp, _ := http.Get(endpoint.ValueString() + "/create")
|
||||
|
||||
fmt.Println("Before the call")
|
||||
fmt.Println(hResp.Body)
|
||||
|
||||
hResp, err := http.Get(endpoint.ValueString() + "/create")
|
||||
|
||||
fmt.Println("After the call")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if hResp.Close == false {
|
||||
fmt.Println("http closed")
|
||||
}
|
||||
//End specific stuff
|
||||
|
||||
//log the creation of the resource in the terraform logging system
|
||||
tflog.Trace(ctx, "created a receita resource")
|
||||
|
@ -157,7 +148,13 @@ func (r *ReceitaResource) Update(ctx context.Context, req resource.UpdateRequest
|
|||
return
|
||||
}
|
||||
|
||||
//Do specific update stuff
|
||||
// Do specific stuff
|
||||
endpoint := r.providerData.Model.Endpoint
|
||||
hResp, _ := http.Get(endpoint.ValueString() + "/update")
|
||||
|
||||
fmt.Println(hResp.Body)
|
||||
|
||||
//End specific stuff
|
||||
|
||||
//Finally update the terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
|
@ -169,6 +166,14 @@ func (r *ReceitaResource) Delete(ctx context.Context, req resource.DeleteRequest
|
|||
// Load tf state into the model
|
||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
||||
|
||||
// Do specific stuff
|
||||
endpoint := r.providerData.Model.Endpoint
|
||||
hResp, _ := http.Get(endpoint.ValueString() + "/delete")
|
||||
|
||||
fmt.Println(hResp.Body)
|
||||
|
||||
//End specific stuff
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue