2021-11-25 13:57:31 +00:00
|
|
|
package terraform
|
2021-08-04 10:16:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-12-06 13:29:39 +00:00
|
|
|
"github.com/snyk/driftctl/pkg/terraform"
|
|
|
|
"github.com/snyk/driftctl/test/schemas"
|
2021-08-04 10:16:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// You can use this test function to create a schema file for a given provider in a given version
|
|
|
|
// You may want to update part of this code to change provider and version to generate desired schema
|
|
|
|
// To use this test you should run this command from the repository root
|
2021-11-25 13:57:31 +00:00
|
|
|
// DCTL_UPDATE_TEST_SCHEMA=true go test ./test/terraform
|
2021-08-04 10:16:06 +00:00
|
|
|
// You may need to setup proper environment variable to make the terraform provider work
|
2021-11-25 13:57:31 +00:00
|
|
|
// DCTL_UPDATE_TEST_SCHEMA=true AWS_PROFILE=myprofile go test ./test/terraform
|
2021-08-04 10:16:06 +00:00
|
|
|
func TestCreateNewSchema(t *testing.T) {
|
|
|
|
|
|
|
|
if os.Getenv("DCTL_UPDATE_TEST_SCHEMA") != "true" {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
providerLibrary := terraform.NewProviderLibrary()
|
|
|
|
|
|
|
|
// Replace this with provider you want to create schema
|
2021-11-25 13:57:31 +00:00
|
|
|
realProvider, _ := InitTestAwsProvider(providerLibrary, "3.19.0")
|
2021-08-04 10:16:06 +00:00
|
|
|
|
|
|
|
err := realProvider.Init()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-11-25 13:57:31 +00:00
|
|
|
err = schemas.WriteTestSchema(realProvider.Schema(), realProvider.Name(), realProvider.Version())
|
2021-08-04 10:16:06 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|