Documentation ¶
Overview ¶
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: MPL-2.0
Index ¶
- Constants
- Variables
- func AccTestPreCheck(t *testing.T)
- func AccTestPreCheck_AdcCredentialsOnly(t *testing.T)
- func AddressWithPrefixLength(prefixLength int) func(*AddressSettings)
- func BoostrapSharedRepositoryGroup(t *testing.T, ...) string
- func BootstrapAllPSARole(t *testing.T, prefix string, agentNames []string, role string) bool
- func BootstrapAllPSARoles(t *testing.T, prefix string, agentNames, roles []string) bool
- func BootstrapComputeStoragePool(t *testing.T, storagePoolName, storagePoolType string) string
- func BootstrapConfig(t *testing.T) *transport_tpg.Config
- func BootstrapDeveloperConnection(t *testing.T, connectionId, location, tokenResource string, ...) string
- func BootstrapFirewallForDataprocSharedNetwork(t *testing.T, firewallName string, networkName string) string
- func BootstrapFolder(t *testing.T, folderDisplayName string) *resourceManagerV3.Folder
- func BootstrapGitRepository(t *testing.T, ...) string
- func BootstrapIamMembers(t *testing.T, members []IamMember)
- func BootstrapNetworkAttachment(t *testing.T, networkAttachmentName string, subnetName string) string
- func BootstrapPSARole(t *testing.T, prefix, agentName, role string) bool
- func BootstrapPSARoles(t *testing.T, prefix, agentName string, roles []string) bool
- func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, services []string) *cloudresourcemanager.Project
- func BootstrapProjectWithParent(t *testing.T, projectID string, billingAccount string, ...) *cloudresourcemanager.Project
- func BootstrapServiceAccount(t *testing.T, testId, testRunner string) string
- func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*cloudresourcemanager.Project
- func BootstrapSharedCaPoolInLocation(t *testing.T, location string) string
- func BootstrapSharedCodeRepositoryIndex(t *testing.T, codeRepositoryIndexId, location, kmsKey string, ...) string
- func BootstrapSharedSQLInstanceBackupRun(t *testing.T) string
- func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string, params ...func(*ServiceNetworkSettings)) string
- func BootstrapSharedTestADDomain(t *testing.T, testId string, networkName string) string
- func BootstrapSharedTestGlobalAddress(t *testing.T, testId string, params ...func(*AddressSettings)) string
- func BootstrapSharedTestNetwork(t *testing.T, testId string) string
- func BootstrapSharedTestTagKey(t *testing.T, testId string) string
- func BootstrapSharedTestTagValue(t *testing.T, testId string, tagKey string) string
- func BootstrapSubnet(t *testing.T, subnetName string, networkName string) string
- func BootstrapSubnetForDataprocBatches(t *testing.T, subnetName string, networkName string) string
- func BootstrapSubnetWithFirewallForDataprocBatches(t *testing.T, testId string, subnetName string) string
- func BootstrapSubnetWithOverrides(t *testing.T, subnetName string, networkName string, ...) string
- func CheckDataSourceStateMatchesResourceState(dataSourceName, resourceName string) func(*terraform.State) error
- func CheckDataSourceStateMatchesResourceStateWithIgnores(dataSourceName, resourceName string, ignoreFields map[string]struct{}) func(*terraform.State) error
- func CreateZIPArchiveForCloudFunctionSource(t *testing.T, sourcePath string) string
- func ExpectNoDelete() plancheck.PlanCheck
- func GenerateCloudKmsServiceIdentity(config *transport_tpg.Config, projectNum string) (string, error)
- func GenerateFakeCredentialsJson(testId string) string
- func GetAccessTokenFromTestCredsFromEnv(t *testing.T) string
- func GetSDKProvider(testName string) *schema.Provider
- func GetTestProject(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)
- func GetTestRegion(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)
- func GoogleProviderConfig(t *testing.T) *transport_tpg.Config
- func HandleVCRConfiguration(ctx context.Context, testName string, rndTripper http.RoundTripper, ...) (time.Duration, http.RoundTripper, fwDiags.Diagnostics)
- func IsVcrEnabled() bool
- func MuxedProviders(testName string) (func() tfprotov5.ProviderServer, error)
- func NewFrameworkTestProvider(testName string, primary *schema.Provider) *frameworkTestProvider
- func NewVcrMatcherFunc(ctx context.Context) func(r *http.Request, i cassette.Request) bool
- func Nprintf(format string, params map[string]interface{}) string
- func ProtoV5ProviderBetaFactories(t *testing.T) map[string]func() (tfprotov5.ProviderServer, error)
- func ProtoV5ProviderFactories(t *testing.T) map[string]func() (tfprotov5.ProviderServer, error)
- func RandInt(t *testing.T) int
- func RandString(t *testing.T, length int) string
- func ServiceNetworkWithParentService(parentService string) func(*ServiceNetworkSettings)
- func ServiceNetworkWithPrefixLength(prefixLength int) func(*ServiceNetworkSettings)
- func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *transport_tpg.Config) (string, error)
- func SetupTestEnvs(t *testing.T, envValues map[string]string)
- func SkipIfVcr(t *testing.T)
- func SleepInSecondsForTest(t int) resource.TestCheckFunc
- func TestBucketName(t *testing.T) string
- func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc
- func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc
- func UnsetTestProviderConfigEnvs(t *testing.T)
- func VcrTest(t *testing.T, c resource.TestCase)
- type AddressSettings
- type BootstrappedKMS
- func BootstrapKMSKey(t *testing.T) BootstrappedKMS
- func BootstrapKMSKeyInLocation(t *testing.T, locationID string) BootstrappedKMS
- func BootstrapKMSKeyWithPurpose(t *testing.T, purpose string) BootstrappedKMS
- func BootstrapKMSKeyWithPurposeInLocation(t *testing.T, purpose, locationID string) BootstrappedKMS
- func BootstrapKMSKeyWithPurposeInLocationAndName(t *testing.T, purpose, locationID, keyShortName string) BootstrappedKMS
- type BootstrappedKMSAutokey
- type IamMember
- type ServiceNetworkSettings
- type VcrSource
Constants ¶
BootstrapSharedCodeRepositoryIndex will create a code repository index if it hasn't been created in the test project.
BootstrapSharedCodeRepositoryIndex returns a persistent code repository index for a test or set of tests.
Deletion of code repository index takes a few minutes, and creation of it currently takes about half an hour. That is the reason to use the shared code repository indexes for test resources.
For bootstrapping Developer Connect git repository link
The default network within GCP already comes pre configured with certain firewall rules open to allow internal communication. As we are boostrapping a network for dataproc tests, we need to additionally open up similar rules to allow the nodes to talk to each other internally as part of their configuration or this will just hang.
SQL Instance names are not reusable for a week after deletion
Variables ¶
var CloudKmsSrviceName = "cloudkms.googleapis.com"
var DefaultKeyHandleName = "eed58b7b-20ad-4da8-ad85-ba78a0d5ab87"
var DefaultKeyHandleResourceType = "compute.googleapis.com/Disk"
"ENCRYPT_DECRYPT": "tftest-shared-key-1",
"ASYMMETRIC_SIGN": "tftest-shared-sign-key-1",
"ASYMMETRIC_DECRYPT": "tftest-shared-decrypt-key-1",
}var TestAccProviders map[string]*schema.Provider
Functions ¶
func AccTestPreCheck ¶
func AccTestPreCheck_AdcCredentialsOnly ¶
AccTestPreCheck_AdcCredentialsOnly is a PreCheck function for acceptance tests that use ADCs when
func AddressWithPrefixLength ¶
func AddressWithPrefixLength(prefixLength int) func(*AddressSettings)
func BootstrapAllPSARole ¶
BootstrapAllPSARole is a version of BootstrapAllPSARoles for granting a single role to multiple service agents.
func BootstrapAllPSARoles ¶
BootstrapAllPSARoles ensures that the given project's IAM policy grants the given service agents the given roles. prefix is usually "service-" and indicates the service agent should have the given prefix before the project number. This is important to bootstrap because using iam policy resources means that deleting them removes permissions for concurrent tests. Return whether the bindings changed.
func BootstrapConfig ¶
func BootstrapConfig(t *testing.T) *transport_tpg.Config
BootstrapConfig returns a Config pulled from the environment.
func BootstrapDeveloperConnection ¶
func BootstrapDeveloperConnection(t *testing.T, connectionId, location, tokenResource string, appInstallationId int) string
For bootstrapping Developer Connect connection resources
func BootstrapFolder ¶
func BootstrapFolder(t *testing.T, folderDisplayName string) *resourceManagerV3.Folder
BootstrapFolder creates or get a folder having a input folderDisplayName within a TestOrgEnv
func BootstrapGitRepository ¶
func BootstrapIamMembers ¶
BootstrapIamMembers ensures that a given set of member/role pairs exist in the default test project. This should be used to avoid race conditions that can happen on the default project due to parallel tests managing the same member/role pairings. Members will have `{project_number}` replaced with the default test project's project number.
func BootstrapPSARole ¶
BootstrapPSARole is a simplified version of BootstrapPSARoles for granting a single role to a single service agent.
func BootstrapPSARoles ¶
BootstrapPSARoles is a version of BootstrapAllPSARoles for granting roles to a single service agent.
func BootstrapProject ¶
func BootstrapProject(t *testing.T, projectIDPrefix, billingAccount string, services []string) *cloudresourcemanager.Project
BootstrapProject will create or get a project named "<projectIDPrefix><projectIDSuffix>" that will persist across test runs, where projectIDSuffix is based off of getTestProjectFromEnv(). The reason for the naming is to isolate bootstrapped projects by test environment. Given the existing projects being used by our team, the prefix provided to this function can be no longer than 18 characters.
func BootstrapProjectWithParent ¶
func BootstrapProjectWithParent(t *testing.T, projectID string, billingAccount string, parent *cloudresourcemanager.ResourceId, services []string) *cloudresourcemanager.Project
func BootstrapServiceAccount ¶
A separate testId should be used for each test, to create separate service accounts for each, and avoid race conditions where the policy of the same service account is being modified by 2 tests at once. This is needed as long as the function overwrites the policy on every run.
func BootstrapServicePerimeterProjects ¶
func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*cloudresourcemanager.Project
func BootstrapSharedSQLInstanceBackupRun ¶
BootstrapSharedSQLInstanceBackupRun will return a shared SQL db instance that has a backup created for it.
func BootstrapSharedServiceNetworkingConnection ¶
func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string, params ...func(*ServiceNetworkSettings)) string
BootstrapSharedServiceNetworkingConnection will create a shared network if it hasn't been created in the test project, a global address if it hasn't been created in the test project, and a service networking connection if it hasn't been created in the test project.
params are the functions to set compute global address
BootstrapSharedServiceNetworkingConnection returns a persistent compute network name for a test or set of tests.
To delete a service networking connection, all of the service instances that use that connection must be deleted first. After the service instances are deleted, some service producers delay the deletion utnil a waiting period has passed. For example, after four days that you delete a SQL instance, the service networking connection can be deleted. That is the reason to use the shared service networking connection for test resources. https://cloud.google.com/vpc/docs/configure-private-services-access#removing-connection
testId specifies the test for which a shared network and a global address are used/initialized.
func BootstrapSharedTestGlobalAddress ¶
func BootstrapSharedTestGlobalAddress(t *testing.T, testId string, params ...func(*AddressSettings)) string
params are the functions to set compute global address
func BootstrapSharedTestNetwork ¶
BootstrapSharedTestNetwork will return a persistent compute network for a test or set of tests.
Usage 1 Resources like service_networking_connection use a consumer network and create a complementing tenant network which we don't control. These tenant networks never get cleaned up and they can accumulate to the point where a limit is reached for the organization. By reusing a consumer network across test runs, we can reduce the number of tenant networks that are needed. See b/146351146 for more context.
Usage 2 Bootstrap networks used in tests (gke clusters, dataproc clusters...) to avoid traffic to the default network
testId specifies the test for which a shared network is used/initialized. Note that if the network is being used for a service_networking_connection, the same testId should generally not be used across tests, to avoid race conditions where multiple tests attempt to modify the connection at once.
Returns the name of a network, creating it if it hasn't been created in the test project.
func BootstrapSubnet ¶
func ExpectNoDelete ¶
func GenerateCloudKmsServiceIdentity ¶
func GenerateCloudKmsServiceIdentity(config *transport_tpg.Config, projectNum string) (string, error)
GenerateCloudKmsServiceIdentity generates cloud kms service identity within a project
func GenerateFakeCredentialsJson ¶
Returns a fake credentials JSON string with the client_email set to a test-specific value
func GetSDKProvider ¶
GetSDKProvider gets the SDK provider for use in acceptance tests If VCR is in use, the configure function is overwritten. See usage in MuxedProviders
func GetTestProject ¶
func GetTestProject(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)
GetTestProject has the same logic as the provider's GetProject, to be used in tests.
func GetTestRegion ¶
func GetTestRegion(is *terraform.InstanceState, config *transport_tpg.Config) (string, error)
GetTestRegion has the same logic as the provider's GetRegion, to be used in tests.
func GoogleProviderConfig ¶
func GoogleProviderConfig(t *testing.T) *transport_tpg.Config
GoogleProviderConfig returns a configured SDKv2 provider. This function is typically used in CheckDestroy functions in acceptance tests. The provider client is used to make GET requests to check a resource is destroyed. Either a preexisting configured SDKv2 provider for the given test name is returned, or a new one is configured with empty (but non-nil) terraform.ResourceConfig
func HandleVCRConfiguration ¶
func HandleVCRConfiguration(ctx context.Context, testName string, rndTripper http.RoundTripper, pollInterval time.Duration) (time.Duration, http.RoundTripper, fwDiags.Diagnostics)
HandleVCRConfiguration configures the recorder (github.com/dnaeon/go-vcr/recorder) used in the VCR test This includes:
- Setting the recording/replaying mode
- Determining the path to the file API interactions will be recorded to/read from
- Determining the logic used to match requests against recorded HTTP interactions (see rec.SetMatcher)
func IsVcrEnabled ¶
func IsVcrEnabled() bool
func MuxedProviders ¶
func MuxedProviders(testName string) (func() tfprotov5.ProviderServer, error)
MuxedProviders returns the correct test provider (between the sdk version or the framework version)
func NewVcrMatcherFunc ¶
NewVcrMatcherFunc returns a function used for matching HTTP requests with data recorded in VCR cassettes
func Nprintf ¶
This is a Printf sibling (Nprintf; Named Printf), which handles strings like Nprintf("Hello %{target}!", map[string]interface{}{"target":"world"}) == "Hello world!". This is particularly useful for generated tests, where we don't want to use Printf, since that would require us to generate a very particular ordering of arguments.
func ProtoV5ProviderBetaFactories ¶
ProtoV5ProviderBetaFactories returns the same as ProtoV5ProviderFactories only the provider is mapped with "google-beta" to ensure that registry examples use `google-beta` if the example is versioned as beta; normal beta tests should continue to use ProtoV5ProviderFactories
func ProtoV5ProviderFactories ¶
ProtoV5ProviderFactories returns a muxed ProviderServer that uses the provider code from this repo (SDK and plugin-framework). Used to set ProtoV5ProviderFactories in a resource.TestStep within an acceptance test.
func ServiceNetworkWithParentService ¶
func ServiceNetworkWithParentService(parentService string) func(*ServiceNetworkSettings)
func ServiceNetworkWithPrefixLength ¶
func ServiceNetworkWithPrefixLength(prefixLength int) func(*ServiceNetworkSettings)
func SetupProjectsAndGetAccessToken ¶
func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *transport_tpg.Config) (string, error)
func SkipIfVcr ¶
Some tests fail during VCR. One common case is race conditions when creating resources. If a test config adds two fine-grained resources with the same parent it is undefined which will be created first, causing VCR to fail ~50% of the time
func SleepInSecondsForTest ¶
func SleepInSecondsForTest(t int) resource.TestCheckFunc
func TestBucketName ¶
func TestCheckAttributeValuesEqual ¶
func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc
TestCheckAttributeValuesEqual compares two string pointers, which have been used to retrieve attribute values from the test's state.
func TestExtractResourceAttr ¶
func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc
TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value accessible via the attributeValue string pointer.
func UnsetTestProviderConfigEnvs ¶
UnsetProviderConfigEnvs unsets any ENVs in the test environment that configure the provider. The testing package will restore the original values after the test
Types ¶
type AddressSettings ¶
type AddressSettings struct {
PrefixLength int
}
func NewAddressSettings ¶
func NewAddressSettings(options ...func(*AddressSettings)) *AddressSettings
type BootstrappedKMS ¶
type BootstrappedKMS struct { *cloudkms.KeyRing *cloudkms.CryptoKey CryptoKeyVersions []*cloudkms.CryptoKeyVersion }
func BootstrapKMSKey ¶
func BootstrapKMSKey(t *testing.T) BootstrappedKMS
func BootstrapKMSKeyInLocation ¶
func BootstrapKMSKeyInLocation(t *testing.T, locationID string) BootstrappedKMS
func BootstrapKMSKeyWithPurpose ¶
func BootstrapKMSKeyWithPurpose(t *testing.T, purpose string) BootstrappedKMS
BootstrapKMSKeyWithPurpose returns a KMS key in the "global" location. See BootstrapKMSKeyWithPurposeInLocation.
func BootstrapKMSKeyWithPurposeInLocation ¶
func BootstrapKMSKeyWithPurposeInLocation(t *testing.T, purpose, locationID string) BootstrappedKMS
* * BootstrapKMSKeyWithPurposeInLocation will return a KMS key in a * particular location with the given purpose that can be used * in tests that are testing KMS integration with other resources. * * This will either return an existing key or create one if it hasn't been created * in the project yet. The motivation is because keyrings don't get deleted and we * don't want a linear growth of disabled keyrings in a project. We also don't want * to incur the overhead of creating a new project for each test that needs to use * a KMS key. *
func BootstrapKMSKeyWithPurposeInLocationAndName ¶
func BootstrapKMSKeyWithPurposeInLocationAndName(t *testing.T, purpose, locationID, keyShortName string) BootstrappedKMS
type BootstrappedKMSAutokey ¶
type BootstrappedKMSAutokey struct { *cloudkms.AutokeyConfig *cloudkms.KeyHandle }
func BootstrapKMSAutokeyKeyHandle ¶
func BootstrapKMSAutokeyKeyHandle(t *testing.T) BootstrappedKMSAutokey
func BootstrapKMSAutokeyKeyHandleWithLocation ¶
func BootstrapKMSAutokeyKeyHandleWithLocation(t *testing.T, locationID string) BootstrappedKMSAutokey
type ServiceNetworkSettings ¶
func NewServiceNetworkSettings ¶
func NewServiceNetworkSettings(options ...func(*ServiceNetworkSettings)) *ServiceNetworkSettings