Terraform Terratest - undefined Destroy function error [closed] - go

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 14 days ago.
Improve this question
Tried to run terratest over terraform file which invokes a aws instance and host a static website but post running this terratest module, it gives an undefined error for destroy function.
Terratest code:
`package test
import (
"fmt"
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
"github.com/gruntwork-io/terratest/modules/terraform"
"testing"
"time"
)
func TestTerraformHelloWorldExample(t *testing.T) {
t.Parallel()
// Construct the terraform options with default retryable errors to handle the most common
// retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// Set the path to the Terraform code that will be tested.
TerraformDir: "../project-3/webserver",
})
terraform.InitAndApply(t, terraformOptions)
defer terraform.Destory(t, terraformOptions)
publicIp := terraform.Output(t, terraformOptions, "public_ip")
url := fmt.Sprintf("http://%s:8080", publicIp)
http_helper.HttpGetWithRetry(t, url, nil, 200, "I have made a Terraform module", 30, 5*time.Second)
}
`
~~~~~~~~~~~~
Output when I ran the test :
> go test webserver_test.go
# command-line-arguments [command-line-arguments.test]
./webserver_test.go:23:18: undefined: terraform.Destory
FAIL command-line-arguments [build failed]
FAIL
Tried to figure out why this is an issue but not able to get root cause. Could someone please help.
I did check the documentation and couple of tutorial video but didn't get much insight on the issue.

Seems a typo, so try:
defer terraform. Destroy(t, terraformOptions)
instead of
defer terraform.Destory(t, terraformOptions)
See https://github.com/gruntwork-io/terratest/blob/e1570b571f726e7d2389b059519101a345b442d6/modules/terraform/destroy.go#L9

Related

What causes urn:acme:error:unauthorized 403 error in golang's acme/autocert?

The full error message is:
403 urn:acme:error:unauthorized: Account creation on ACMEv1 is
disabled. Please upgrade your ACME client to a version that supports
ACMEv2 / RFC 8555. See
https://community.letsencrypt.org/t/end-of-life-plan-for-acmev1/88430
for details
And I've googled this and reviewed that link, but I'm just using:
golang.org/x/crypto/acme/autocert
package in a very normal way:
package main
import (
"crypto/tls"
"net/http"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/acme/autocert"
)
func main() {
router := gin.Default()
hosts := []string{"yourdomain.com"}
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(hosts...),
Cache: autocert.DirCache("/certs"),
}
server := &http.Server{
Addr: ":https",
Handler: router,
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
server.ListenAndServeTLS("", "")
}
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
I tried getting the very latest version of golang, but still same problem.
I changed my DNS for my hosts to this new server's ip and the hostname of the server is correct.
Far as I can tell, it's 100% identical to the previous working server but with a new IP.
Is golang's acme/autocert really this out of date and not using ACMEv2?
This statement:
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
Might indicate that you're building against an older version of golang.org/x/crypto - check your go.mod file and ensure you're using a fairly recent version. I completed a project recently that uses almost identical code. The require in my go.mod looks like this:
golang.org/x/crypto v0.0.0-20200602180216-279210d13fed

Unable to build the app in golang with oracle db

I am a beginner in go lang development and I try to connect the cloud oracle DB from go server(using 'github.com/godror/godror' package).
I install the Oracle instant client and set the environment path also.
Go server is running and able to establish the connection and queries. But when I am building a production app got these errors.
Command: env GOOS=linux GOARCH=amd64 go build -o odb db_main.go
../github.com/godror/godror/orahlp.go:452:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:461:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:479:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:480:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:481:30: undefined: ObjectType
../github.com/godror/godror/orahlp.go:482:31: undefined: Event
../github.com/godror/godror/orahlp.go:482:42: undefined: SubscriptionOption
../github.com/godror/godror/orahlp.go:482:64: undefined: Subscription
../github.com/godror/godror/orahlp.go:483:10: undefined: StartupMode
../github.com/godror/godror/orahlp.go:484:11: undefined: ShutdownMode
../github.com/godror/godror/orahlp.go:484:11: too many errors```
My server code(db_main.go)
```package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
_ "github.com/godror/godror"
)
// VersionInfo,ObjectType,Event,SubscriptionOption,Subscription,StartupMode,ShutdownMode
var db *sql.DB
func main() {
var err error
db, err = sql.Open("godror", "xyz/abc#13.43.11.8:1521/sampledb")
if err != nil {
log.Println("Error")
fmt.Println(err)
return
}
defer db.Close()
port := ":8000"
http.HandleFunc("/insert", InsertData)
http.HandleFunc("/list", GetList)
log.Println("Tranzo-Shahi Oracle DB running in ", port)
httpErr := http.ListenAndServe(port, nil)
if httpErr != nil {
log.Println("Tranzo-Shahi Oracle DB Error: ", httpErr.Error())
}
}
Run env GOOS=linux GOARCH=amd64 go build -o odb and don't specify any file. If you do specify one, like db_main.go then you need to specify all the files it the package that must be included in the build.
Unfortunately original question has no mentioning of where the build run. It's important to know.
godror documentation points to possible problems when you try cross-compile your code. It's in their documentation: Cgo is required, so cross-compilation is hard, and you cannot set CGO_ENABLED=0!
I would suggest to run your build on Linux machine. (Verify it has gcc installed.)
Run your build as env CGO_ENABLED=1 go build -o odb

Why am I getting ‘panic: runtime error: invalid memory address or nil pointer dereference’ accessing Firestore on new computer? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I get a Panic if I attempt to run the tests or runthe app directly via: go run main.go
The code works great on my old Macbook Pro. It panics on my new Macbook Pro.
I believe the error has Something to do with accessing the Firestore datastore but I'm not sure what's going wrong.
I'm running the same code so datastore Keys and everything else should be identical.
Here is the Github repo:
https://github.com/golangnewb/FirestoreTestHttp
Working Computer:
go version go1.11.2 darwin/amd64
Panic Computer:
go version go1.13.5 darwin/amd64
❯ go test
--- FAIL: TestCities (0.01s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x14d557a]
goroutine 6 [running]:
testing.tRunner.func1(0xc000312200)
/usr/local/go/src/testing/testing.go:874 +0x3a3
panic(0x15ac100, 0x1b3e740)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
cloud.google.com/go/firestore.(*Client).path(...)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:107
cloud.google.com/go/firestore.(*Client).Collection(0x0, 0x1677ac0, 0x6, 0x14)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:122 +0x9a
_/Users/XXX/Dropbox/go/src/firestoreTestHttp.addCitiesFirestore(0x5e4c4feb, 0xc000064760)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/city_handlers_test.go:218 +0x13d
_/Users/XXX/Dropbox/go/src/firestoreTestHttp.TestCities(0xc000312200)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/city_handlers_test.go:19 +0x26
testing.tRunner(0xc000312200, 0x16a1c98)
/usr/local/go/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:960 +0x350
exit status 2
FAIL _/Users/XXX/Dropbox/go/src/firestoreTestHttp 0.165s
Here is the panic if I try to run via:
❯ go run main.go
2020/02/18 17:19:39 http: panic serving [::1]:60479: runtime error: invalid memory address or nil pointer dereference
goroutine 9 [running]:
net/http.(*conn).serve.func1(0xc00027c6e0)
/usr/local/go/src/net/http/server.go:1767 +0x139
panic(0x15a69c0, 0x1b39a50)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
cloud.google.com/go/firestore.(*Client).path(...)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:107
cloud.google.com/go/firestore.(*Client).Collection(0x0, 0x16728ba, 0x6, 0x14)
/Users/XXX/go/src/cloud.google.com/go/firestore/client.go:122 +0x9a
main.indexHandler(0x1744360, 0xc000322000, 0xc0002c8200)
/Users/XXX/Dropbox/go/src/firestoreTestHttp/main.go:50 +0xa2
net/http.HandlerFunc.ServeHTTP(0x169da80, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2007 +0x44
net/http.(*ServeMux).ServeHTTP(0xc0002ea100, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2387 +0x1bd
net/http.serverHandler.ServeHTTP(0xc000312000, 0x1744360, 0xc000322000, 0xc0002c8200)
/usr/local/go/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc00027c6e0, 0x17457a0, 0xc00008cf80)
/usr/local/go/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2928 +0x384
Although I dont feel well in Go I will try a shot. If I am wrong just let me know.
From the error it seems that Client is nil. In attached Git repo in main you are logging that it should be set as environment variable GCLOUD_PROJECT, however I haven't found any so.Getenv function that gets this value. Maybe this value is wrong...?
So I guess this statement client, _ := firestore.NewClient(ctx, projectID) is being called with wrong projectID. In the statement error handling is omitted, so we do not know if the client has been created properly. If it was not created, that we should get such error.
Maybe you should add error handling like in example in Go Firestore Reference, to ensure that there is no error during client creation.
I hope this will help you!

Go compile error?

I'm trying to compile a fork of cuttle that merges this pull request
by running
# GOPATH=`pwd` /usr/local/go/bin/go get github.com/andresdouglas/cuttle
# github.com/andresdouglas/cuttle
src/github.com/andresdouglas/cuttle/main.go:103: zone.GetController(r.URL.Host, r.URL.Path).Acquire() used as value
Here is the offending line
I have no experience with Go. Is that an error? It doesn't seem to update the compiled binary.
Check the source code here:
// Acquire permission from NoopControl.
// Permission is granted immediately since it does not perform any rate limit.
func (c *NoopControl) Acquire() {
log.Debugf("NoopControl[%s]: Seeking permission.", c.Label)
log.Debugf("NoopControl[%s]: Granted permission.", c.Label)
}
There is NO return value of func (c *NoopControl) Acquire().

what "unknown tls.Config field" Error Means?

While I compile a go language code using "go install", I got the following error:
./xyzcheck.go:34: unknown tls.Config field 'EarlyCCS' in struct literal
here is the code that make that error
conn, err = tls.Dial("tcp", target, &tls.Config{InsecureSkipVerify: true, EarlyCCS: 2})
if err == nil {
fmt.Printf("\x1b[31mXYZ Check is OK.\x1b[0m\n")
os.Exit(1)
}
I googled this error but no luck.
If anyone can tell me what is the reason for this error? and how can I fix it. it will be great.
Thanks
ABC: 2 is not a valid parameter for config. There is documentation on config settings for tls here: http://golang.org/pkg/crypto/tls/#Config
The author has a patch that needs to be applied to the tls package. This was clearly explained on his blog page where you obtained this script.
Apply the patch to the tls package, re-run the script and it will work.

Resources