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 AddressWithPrefixLength(prefixLength int) func(*AddressSettings)
- func BootstrapAllPSARole(t *testing.T, prefix string, agentNames []string, role string) bool
- func BootstrapAllPSARoles(t *testing.T, prefix string, agentNames, roles []string) bool
- func BootstrapConfig(t *testing.T) *transport_tpg.Config
- func BootstrapFirewallForDataprocSharedNetwork(t *testing.T, firewallName string, networkName string) string
- 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 BootstrapServiceAccount(t *testing.T, project, testRunner string) string
- func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*cloudresourcemanager.Project
- func BootstrapSharedCaPoolInLocation(t *testing.T, location 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 BootstrapSubnet(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 GenerateFakeCredentialsJson(testId string) string
- func GetFwTestProvider(t *testing.T) *frameworkTestProvider
- 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) *frameworkTestProvider
- 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 ServiceNetworkSettings
- type VcrSource
Constants ¶
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 ¶
"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 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 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 BootstrapServiceAccount ¶
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 conneciton, 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 thest resources. https://cloud.google.com/vpc/docs/configure-private-services-access#removing-connection
testId specifies the test for which a shared network and a gobal 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 GenerateFakeCredentialsJson ¶
Returns a fake credentials JSON string with the client_email set to a test-specific value
func GetFwTestProvider ¶
func GetSDKProvider ¶
GetSDKProvider gets the SDK provider with an overwritten configure function to be called by 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
func HandleVCRConfiguration ¶
func HandleVCRConfiguration(ctx context.Context, testName string, rndTripper http.RoundTripper, pollInterval time.Duration) (time.Duration, http.RoundTripper, fwDiags.Diagnostics)
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 NewFrameworkTestProvider ¶
func NewFrameworkTestProvider(testName string) *frameworkTestProvider
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 ¶
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 ServiceNetworkSettings ¶
func NewServiceNetworkSettings ¶
func NewServiceNetworkSettings(options ...func(*ServiceNetworkSettings)) *ServiceNetworkSettings