Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ jobs:
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
# Having long retry intervals will ensure that we have few requests done while waiting on call to complete (using time.ParseDuration)
TF_RETRY_DELAY: 30s
- name: Ping on failure
if: ${{ failure() }}
run: |
Expand Down
11 changes: 11 additions & 0 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
Expand Down Expand Up @@ -46,8 +47,18 @@ func NewTestTools(t *testing.T) *TestTools {
require.NoError(t, err)

if !*UpdateCassettes {
// If no recording is happening, the delay to retry to interactions should be 0
tmp := 0 * time.Second
transport.DefaultWaitRetryInterval = &tmp
} else if os.Getenv(env.RetryDelay) != "" {
// Overriding the delay interval is helpful to reduce the amount of requests performed while waiting for a ressource to be available
tmp, err := time.ParseDuration(os.Getenv(env.RetryDelay))
if err != nil {
t.Fatal(err)
}

t.Logf("delay retry set to: %v", tmp)
transport.DefaultWaitRetryInterval = &tmp
}

return &TestTools{
Expand Down
11 changes: 6 additions & 5 deletions internal/acctest/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"regexp"

"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
)

Expand All @@ -22,11 +23,11 @@ var (
)

func init() {
testDomainPtr := flag.String("test-domain", os.Getenv("TF_TEST_DOMAIN"), "Test domain")
testDomainPtr := flag.String("test-domain", os.Getenv(env.TestDomain), "Test domain")
if testDomainPtr != nil && *testDomainPtr != "" {
TestDomain = *testDomainPtr
} else {
logging.L.Infof("environment variable TF_TEST_DOMAIN is required")
logging.L.Infof("environment variable %s is required", env.TestDomain)

return
}
Expand All @@ -43,18 +44,18 @@ func init() {
}

if isReserved {
logging.L.Warningf("TF_TEST_DOMAIN cannot be a Scaleway required domain. Please use another one.")
logging.L.Warningf("%s cannot be a Scaleway required domain. Please use another one.", env.TestDomain)

return
}

logging.L.Infof("start domain record test with domain: %s", TestDomain)

testDomainZonePtr := flag.String("test-domain-zone", os.Getenv("TF_TEST_DOMAIN_ZONE"), "Test domain zone")
testDomainZonePtr := flag.String("test-domain-zone", os.Getenv(env.TestDomainZone), "Test domain zone")
if testDomainZonePtr != nil && *testDomainZonePtr != "" {
TestDomainZone = *testDomainZonePtr
} else {
logging.L.Infof("environment variable TF_TEST_DOMAIN_ZONE is required")
logging.L.Infof("environment variable %s is required", env.TestDomainZone)

return
}
Expand Down
3 changes: 2 additions & 1 deletion internal/acctest/vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/strcase"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
"github.com/stretchr/testify/require"
Expand All @@ -24,7 +25,7 @@ import (
)

// UpdateCassettes will update all cassettes of a given test
var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")
var UpdateCassettes = flag.Bool("cassettes", os.Getenv(env.UpdateCassettes) == "true", "Record Cassettes")

// SensitiveFields is a map with keys listing fields that should be anonymized
// value will be set in place of its old value
Expand Down
17 changes: 17 additions & 0 deletions internal/env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Package env contains a list of environment variables used to modify the behaviour of the provider
package env

const (
// RetryDelay is a duration string (parsed with time.ParseDuration) will change how long the SDK will wait between to attempts
RetryDelay = "TF_RETRY_DELAY"
// UpdateCassettes if set to "true" will trigger the cassettes to be recorded
UpdateCassettes = "TF_UPDATE_CASSETTES"
// TestDomain is the DNS domain used during our tests
TestDomain = "TF_TEST_DOMAIN"
// TestDomainZone is the DNS zone used during our tests
TestDomainZone = "TF_TEST_DOMAIN_ZONE"
// AppendUserAgent is appended to the user agent of the underlying SDK go
AppendUserAgent = "TF_APPEND_USER_AGENT"
// AccDomainRegistration if set to "true" will trigger acceptance test for domain registration
AccDomainRegistration = "TF_ACC_DOMAIN_REGISTRATION"
)
4 changes: 2 additions & 2 deletions internal/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
"github.com/scaleway/terraform-provider-scaleway/v2/version"
)

const (
appendUserAgentEnvVar = "TF_APPEND_USER_AGENT"
CredentialsSourceEnvironment = "Environment variable"
CredentialsSourceDefault = "Default"
CredentialsSourceActiveProfile = "Active Profile in config.yaml"
Expand Down Expand Up @@ -197,7 +197,7 @@ type Config struct {
func customizeUserAgent(providerVersion string, terraformVersion string) string {
userAgent := fmt.Sprintf("terraform-provider/%s terraform/%s", providerVersion, terraformVersion)

if appendUserAgent := os.Getenv(appendUserAgentEnvVar); appendUserAgent != "" {
if appendUserAgent := os.Getenv(env.AppendUserAgent); appendUserAgent != "" {
userAgent += " " + appendUserAgent
}

Expand Down
5 changes: 3 additions & 2 deletions internal/services/domain/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"
domainSDK "github.com/scaleway/scaleway-sdk-go/api/domain/v2beta1"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/domain"
)
Expand Down Expand Up @@ -268,9 +269,9 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
// If `TF_UPDATE_CASSETTES=true`, the test is **only executed if `TF_ACC_DOMAIN_REGISTRATION=true`**.
// Otherwise, the test is skipped to prevent unintended domain reservations.
func shouldBeSkipped() bool {
if os.Getenv("TF_UPDATE_CASSETTES") == "false" {
if os.Getenv(env.UpdateCassettes) == "false" {
return false
}

return os.Getenv("TF_ACC_DOMAIN_REGISTRATION") != "true"
return os.Getenv(env.AccDomainRegistration) != "true"
}
Loading