terratest: github.com/gruntwork-io/terratest/modules/gcp Index | Files

package gcp

import "github.com/gruntwork-io/terratest/modules/gcp"

Package gcp allows interaction with Google Cloud Platform resources.

Index

Package Files

cloudbuild.go compute.go gcp.go gcr.go oslogin.go provider.go region.go storage.go

func AssertStorageBucketExists Uses

func AssertStorageBucketExists(t testing.TestingT, name string)

AssertStorageBucketExists checks if the given storage bucket exists and fails the test if it does not.

func AssertStorageBucketExistsE Uses

func AssertStorageBucketExistsE(t testing.TestingT, name string) error

AssertStorageBucketExistsE checks if the given storage bucket exists and returns an error if it does not.

func CreateBuild Uses

func CreateBuild(t testing.TestingT, projectID string, build *cloudbuildpb.Build) *cloudbuildpb.Build

CreateBuild creates a new build blocking until the operation is complete.

func CreateBuildE Uses

func CreateBuildE(t testing.TestingT, projectID string, build *cloudbuildpb.Build) (*cloudbuildpb.Build, error)

CreateBuildE creates a new build blocking until the operation is complete.

func CreateStorageBucket Uses

func CreateStorageBucket(t testing.TestingT, projectID string, name string, attr *storage.BucketAttrs)

CreateStorageBucket creates a Google Cloud bucket with the given BucketAttrs. Note that Google Storage bucket names must be globally unique.

func CreateStorageBucketE Uses

func CreateStorageBucketE(t testing.TestingT, projectID string, name string, attr *storage.BucketAttrs) error

CreateStorageBucketE creates a Google Cloud bucket with the given BucketAttrs. Note that Google Storage bucket names must be globally unique.

func DeleteGCRImageRef Uses

func DeleteGCRImageRef(t testing.TestingT, ref string)

DeleteGCRImageRef deletes a single repo image ref/digest

func DeleteGCRImageRefE Uses

func DeleteGCRImageRefE(t testing.TestingT, ref string) error

DeleteGCRImageRefE deletes a single repo image ref/digest

func DeleteGCRRepo Uses

func DeleteGCRRepo(t testing.TestingT, repo string)

DeleteGCRRepo deletes a GCR repository including all tagged images

func DeleteGCRRepoE Uses

func DeleteGCRRepoE(t testing.TestingT, repo string) error

DeleteGCRRepoE deletes a GCR repository including all tagged images

func DeleteSSHKey Uses

func DeleteSSHKey(t testing.TestingT, user, key string)

DeleteSSHKey will delete an SSH key attached to the provided user identity. The `user` parameter should be the email address of the user. The `key` parameter should be the public key of the SSH key that was uploaded. This will fail the test if there is an error.

func DeleteSSHKeyE Uses

func DeleteSSHKeyE(t testing.TestingT, user, key string) error

DeleteSSHKeyE will delete an SSH key attached to the provided user identity. The `user` parameter should be the email address of the user. The `key` parameter should be the public key of the SSH key that was uploaded.

func DeleteStorageBucket Uses

func DeleteStorageBucket(t testing.TestingT, name string)

DeleteStorageBucket destroys the Google Storage bucket.

func DeleteStorageBucketE Uses

func DeleteStorageBucketE(t testing.TestingT, name string) error

DeleteStorageBucketE destroys the S3 bucket in the given region with the given name.

func EmptyStorageBucket Uses

func EmptyStorageBucket(t testing.TestingT, name string)

EmptyStorageBucket removes the contents of a storage bucket with the given name.

func EmptyStorageBucketE Uses

func EmptyStorageBucketE(t testing.TestingT, name string) error

EmptyStorageBucketE removes the contents of a storage bucket with the given name.

func GetAllGcpRegions Uses

func GetAllGcpRegions(t testing.TestingT, projectID string) []string

GetAllGcpRegions gets the list of GCP regions available in this account.

func GetAllGcpRegionsE Uses

func GetAllGcpRegionsE(t testing.TestingT, projectID string) ([]string, error)

GetAllGcpRegionsE gets the list of GCP regions available in this account.

func GetAllGcpZones Uses

func GetAllGcpZones(t testing.TestingT, projectID string) []string

GetAllGcpZones gets the list of GCP Zones available in this account.

func GetAllGcpZonesE Uses

func GetAllGcpZonesE(t testing.TestingT, projectID string) ([]string, error)

GetAllGcpZonesE gets the list of GCP Zones available in this account.

func GetBuild Uses

func GetBuild(t testing.TestingT, projectID string, buildID string) *cloudbuildpb.Build

GetBuild gets the given build.

func GetBuildE Uses

func GetBuildE(t testing.TestingT, projectID string, buildID string) (*cloudbuildpb.Build, error)

GetBuildE gets the given build.

func GetBuilds Uses

func GetBuilds(t testing.TestingT, projectID string) []*cloudbuildpb.Build

GetBuilds gets the list of builds for a given project.

func GetBuildsE Uses

func GetBuildsE(t testing.TestingT, projectID string) ([]*cloudbuildpb.Build, error)

GetBuildsE gets the list of builds for a given project.

func GetBuildsForTrigger Uses

func GetBuildsForTrigger(t testing.TestingT, projectID string, triggerID string) []*cloudbuildpb.Build

GetBuildsForTrigger gets a list of builds for a specific cloud build trigger.

func GetBuildsForTriggerE Uses

func GetBuildsForTriggerE(t testing.TestingT, projectID string, triggerID string) ([]*cloudbuildpb.Build, error)

GetBuildsForTriggerE gets a list of builds for a specific cloud build trigger.

func GetGoogleCredentialsFromEnvVar Uses

func GetGoogleCredentialsFromEnvVar(t testing.TestingT) string

GetGoogleCredentialsFromEnvVar returns the Credentials for use with testing.

func GetGoogleIdentityEmailEnvVar Uses

func GetGoogleIdentityEmailEnvVar(t testing.TestingT) string

GetGoogleIdentityEmailEnvVar returns a Google identity (user) for use with testing.

func GetGoogleProjectIDFromEnvVar Uses

func GetGoogleProjectIDFromEnvVar(t testing.TestingT) string

GetGoogleProjectIDFromEnvVar returns the Project Id for use with testing.

func GetGoogleRegionFromEnvVar Uses

func GetGoogleRegionFromEnvVar(t testing.TestingT) string

GetGoogleRegionFromEnvVar returns the Region for use with testing.

func GetLoginProfile Uses

func GetLoginProfile(t testing.TestingT, user string) *oslogin.LoginProfile

GetLoginProfile will retrieve the login profile for a user's Google identity. The login profile is a combination of OS Login + gcloud SSH keys and POSIX accounts the user will appear as. Generally, this will only be the OS Login key + account, but `gcloud compute ssh` could create temporary keys and profiles. The `user` parameter should be the email address of the user. This will fail the test if there is an error.

func GetLoginProfileE Uses

func GetLoginProfileE(t testing.TestingT, user string) (*oslogin.LoginProfile, error)

GetLoginProfileE will retrieve the login profile for a user's Google identity. The login profile is a combination of OS Login + gcloud SSH keys and POSIX accounts the user will appear as. Generally, this will only be the OS Login key + account, but `gcloud compute ssh` could create temporary keys and profiles. The `user` parameter should be the email address of the user.

func GetRandomRegion Uses

func GetRandomRegion(t testing.TestingT, projectID string, approvedRegions []string, forbiddenRegions []string) string

GetRandomRegion gets a randomly chosen GCP Region. If approvedRegions is not empty, this will be a Region from the approvedRegions list; otherwise, this method will fetch the latest list of regions from the GCP APIs and pick one of those. If forbiddenRegions is not empty, this method will make sure the returned Region is not in the forbiddenRegions list.

func GetRandomRegionE Uses

func GetRandomRegionE(t testing.TestingT, projectID string, approvedRegions []string, forbiddenRegions []string) (string, error)

GetRandomRegionE gets a randomly chosen GCP Region. If approvedRegions is not empty, this will be a Region from the approvedRegions list; otherwise, this method will fetch the latest list of regions from the GCP APIs and pick one of those. If forbiddenRegions is not empty, this method will make sure the returned Region is not in the forbiddenRegions list.

func GetRandomZone Uses

func GetRandomZone(t testing.TestingT, projectID string, approvedZones []string, forbiddenZones []string, forbiddenRegions []string) string

GetRandomZone gets a randomly chosen GCP Zone. If approvedRegions is not empty, this will be a Zone from the approvedZones list; otherwise, this method will fetch the latest list of Zones from the GCP APIs and pick one of those. If forbiddenZones is not empty, this method will make sure the returned Region is not in the forbiddenZones list.

func GetRandomZoneE Uses

func GetRandomZoneE(t testing.TestingT, projectID string, approvedZones []string, forbiddenZones []string, forbiddenRegions []string) (string, error)

GetRandomZoneE gets a randomly chosen GCP Zone. If approvedRegions is not empty, this will be a Zone from the approvedZones list; otherwise, this method will fetch the latest list of Zones from the GCP APIs and pick one of those. If forbiddenZones is not empty, this method will make sure the returned Region is not in the forbiddenZones list.

func GetRandomZoneForRegion Uses

func GetRandomZoneForRegion(t testing.TestingT, projectID string, region string) string

GetRandomZoneForRegion gets a randomly chosen GCP Zone in the given Region.

func GetRandomZoneForRegionE Uses

func GetRandomZoneForRegionE(t testing.TestingT, projectID string, region string) (string, error)

GetRandomZoneForRegionE gets a randomly chosen GCP Zone in the given Region.

func ImportSSHKey Uses

func ImportSSHKey(t testing.TestingT, user, key string)

ImportSSHKey will import an SSH key to GCP under the provided user identity. The `user` parameter should be the email address of the user. The `key` parameter should be the public key of the SSH key being uploaded. This will fail the test if there is an error.

func ImportSSHKeyE Uses

func ImportSSHKeyE(t testing.TestingT, user, key string) error

ImportSSHKeyE will import an SSH key to GCP under the provided user identity. The `user` parameter should be the email address of the user. The `key` parameter should be the public key of the SSH key being uploaded.

func NewCloudBuildService Uses

func NewCloudBuildService(t testing.TestingT) *cloudbuild.Client

NewCloudBuildService creates a new Cloud Build service, which is used to make Cloud Build API calls.

func NewCloudBuildServiceE Uses

func NewCloudBuildServiceE(t testing.TestingT) (*cloudbuild.Client, error)

NewCloudBuildServiceE creates a new Cloud Build service, which is used to make Cloud Build API calls.

func NewComputeService Uses

func NewComputeService(t testing.TestingT) *compute.Service

NewComputeService creates a new Compute service, which is used to make GCE API calls.

func NewComputeServiceE Uses

func NewComputeServiceE(t testing.TestingT) (*compute.Service, error)

NewComputeServiceE creates a new Compute service, which is used to make GCE API calls.

func NewInstancesService Uses

func NewInstancesService(t testing.TestingT) *compute.InstancesService

NewInstancesService creates a new InstancesService service, which is used to make a subset of GCE API calls.

func NewInstancesServiceE Uses

func NewInstancesServiceE(t testing.TestingT) (*compute.InstancesService, error)

NewInstancesServiceE creates a new InstancesService service, which is used to make a subset of GCE API calls.

func NewOSLoginServiceE Uses

func NewOSLoginServiceE(t testing.TestingT) (*oslogin.Service, error)

NewOSLoginServiceE creates a new OS Login service, which is used to make OS Login API calls.

func RandomValidGcpName Uses

func RandomValidGcpName() string

Return a random, valid name for GCP resources. Many resources in GCP requires lowercase letters only.

func ReadBucketObject Uses

func ReadBucketObject(t testing.TestingT, bucketName string, filePath string) io.Reader

ReadBucketObject reads an object from the given Storage Bucket and returns its contents.

func ReadBucketObjectE Uses

func ReadBucketObjectE(t testing.TestingT, bucketName string, filePath string) (io.Reader, error)

ReadBucketObjectE reads an object from the given Storage Bucket and returns its contents.

func RegionUrlToRegion Uses

func RegionUrlToRegion(zoneUrl string) string

Given a GCP Zone URL formatted like https://www.googleapis.com/compute/v1/projects/project-123456/regions/southamerica-east1, return "southamerica-east1". Todo: Improve sanity checking on this function by using a RegEx with capture groups

func WriteBucketObject Uses

func WriteBucketObject(t testing.TestingT, bucketName string, filePath string, body io.Reader, contentType string) string

WriteBucketObject writes an object to the given Storage Bucket and returns its URL.

func WriteBucketObjectE Uses

func WriteBucketObjectE(t testing.TestingT, bucketName string, filePath string, body io.Reader, contentType string) (string, error)

WriteBucketObjectE writes an object to the given Storage Bucket and returns its URL.

func ZoneUrlToZone Uses

func ZoneUrlToZone(zoneUrl string) string

Given a GCP Zone URL formatted like https://www.googleapis.com/compute/v1/projects/project-123456/zones/asia-east1-b, return "asia-east1-b". Todo: Improve sanity checking on this function by using a RegEx with capture groups

type Image Uses

type Image struct {
    *compute.Image
    // contains filtered or unexported fields
}

Corresponds to a GCP Image (https://cloud.google.com/compute/docs/images)

func FetchImage Uses

func FetchImage(t testing.TestingT, projectID string, name string) *Image

FetchImage queries GCP to return a new instance of the (GCP Compute) Image type

func FetchImageE Uses

func FetchImageE(t testing.TestingT, projectID string, name string) (*Image, error)

FetchImage queries GCP to return a new instance of the (GCP Compute) Image type

func (*Image) DeleteImage Uses

func (i *Image) DeleteImage(t testing.TestingT)

DeleteImage deletes the given Compute Image.

func (*Image) DeleteImageE Uses

func (i *Image) DeleteImageE(t testing.TestingT) error

DeleteImageE deletes the given Compute Image.

type Instance Uses

type Instance struct {
    *compute.Instance
    // contains filtered or unexported fields
}

Corresponds to a GCP Compute Instance (https://cloud.google.com/compute/docs/instances/)

func FetchInstance Uses

func FetchInstance(t testing.TestingT, projectID string, name string) *Instance

FetchInstance queries GCP to return an instance of the (GCP Compute) Instance type

func FetchInstanceE Uses

func FetchInstanceE(t testing.TestingT, projectID string, name string) (*Instance, error)

FetchInstance queries GCP to return an instance of the (GCP Compute) Instance type

func (*Instance) AddSshKey Uses

func (i *Instance) AddSshKey(t testing.TestingT, username string, publicKey string)

Add the given public SSH key to the Compute Instance. Users can SSH in with the given username.

func (*Instance) AddSshKeyE Uses

func (i *Instance) AddSshKeyE(t testing.TestingT, username string, publicKey string) error

Add the given public SSH key to the Compute Instance. Users can SSH in with the given username.

func (*Instance) GetLabels Uses

func (i *Instance) GetLabels(t testing.TestingT) map[string]string

GetLabels returns all the tags for the given Compute Instance.

func (*Instance) GetMetadata Uses

func (i *Instance) GetMetadata(t testing.TestingT) []*compute.MetadataItems

GetMetadata gets the given Compute Instance's metadata

func (*Instance) GetPublicIp Uses

func (i *Instance) GetPublicIp(t testing.TestingT) string

GetPublicIP gets the public IP address of the given Compute Instance.

func (*Instance) GetPublicIpE Uses

func (i *Instance) GetPublicIpE(t testing.TestingT) (string, error)

GetPublicIpE gets the public IP address of the given Compute Instance.

func (*Instance) GetZone Uses

func (i *Instance) GetZone(t testing.TestingT) string

GetZone returns the Zone in which the Compute Instance is located.

func (*Instance) SetLabels Uses

func (i *Instance) SetLabels(t testing.TestingT, labels map[string]string)

SetLabels adds the tags to the given Compute Instance.

func (*Instance) SetLabelsE Uses

func (i *Instance) SetLabelsE(t testing.TestingT, labels map[string]string) error

SetLabelsE adds the tags to the given Compute Instance.

func (*Instance) SetMetadata Uses

func (i *Instance) SetMetadata(t testing.TestingT, metadata map[string]string)

SetMetadata sets the given Compute Instance's metadata

func (*Instance) SetMetadataE Uses

func (i *Instance) SetMetadataE(t testing.TestingT, metadata map[string]string) error

SetLabelsE adds the given metadata map to the existing metadata of the given Compute Instance.

type InstanceGroup Uses

type InstanceGroup interface {
    GetInstanceIds(t testing.TestingT) []string
    GetInstanceIdsE(t testing.TestingT) ([]string, error)
}

type RegionalInstanceGroup Uses

type RegionalInstanceGroup struct {
    *compute.InstanceGroup
    // contains filtered or unexported fields
}

Corresponds to a GCP Regional Instance Group (https://cloud.google.com/compute/docs/instance-groups/)

func FetchRegionalInstanceGroup Uses

func FetchRegionalInstanceGroup(t testing.TestingT, projectID string, region string, name string) *RegionalInstanceGroup

FetchRegionalInstanceGroup queries GCP to return a new instance of the Regional Instance Group type

func FetchRegionalInstanceGroupE Uses

func FetchRegionalInstanceGroupE(t testing.TestingT, projectID string, region string, name string) (*RegionalInstanceGroup, error)

FetchRegionalInstanceGroup queries GCP to return a new instance of the Regional Instance Group type

func (*RegionalInstanceGroup) GetInstanceIds Uses

func (ig *RegionalInstanceGroup) GetInstanceIds(t testing.TestingT) []string

GetInstanceIds gets the IDs of Instances in the given Regional Instance Group.

func (*RegionalInstanceGroup) GetInstanceIdsE Uses

func (ig *RegionalInstanceGroup) GetInstanceIdsE(t testing.TestingT) ([]string, error)

GetInstanceIdsE gets the IDs of Instances in the given Regional Instance Group.

func (*RegionalInstanceGroup) GetInstances Uses

func (ig *RegionalInstanceGroup) GetInstances(t testing.TestingT, projectId string) []*Instance

Return a collection of Instance structs from the given Instance Group

func (*RegionalInstanceGroup) GetInstancesE Uses

func (ig *RegionalInstanceGroup) GetInstancesE(t testing.TestingT, projectId string) ([]*Instance, error)

Return a collection of Instance structs from the given Instance Group

func (*RegionalInstanceGroup) GetPublicIps Uses

func (ig *RegionalInstanceGroup) GetPublicIps(t testing.TestingT, projectId string) []string

GetPublicIps returns a slice of the public IPs from the given Instance Group

func (*RegionalInstanceGroup) GetPublicIpsE Uses

func (ig *RegionalInstanceGroup) GetPublicIpsE(t testing.TestingT, projectId string) ([]string, error)

GetPublicIpsE returns a slice of the public IPs from the given Instance Group

func (*RegionalInstanceGroup) GetRandomInstance Uses

func (ig *RegionalInstanceGroup) GetRandomInstance(t testing.TestingT) *Instance

getRandomInstance returns a randomly selected Instance from the Regional Instance Group

func (*RegionalInstanceGroup) GetRandomInstanceE Uses

func (ig *RegionalInstanceGroup) GetRandomInstanceE(t testing.TestingT) (*Instance, error)

getRandomInstanceE returns a randomly selected Instance from the Regional Instance Group

type ZonalInstanceGroup Uses

type ZonalInstanceGroup struct {
    *compute.InstanceGroup
    // contains filtered or unexported fields
}

Corresponds to a GCP Zonal Instance Group (https://cloud.google.com/compute/docs/instance-groups/)

func FetchZonalInstanceGroup Uses

func FetchZonalInstanceGroup(t testing.TestingT, projectID string, zone string, name string) *ZonalInstanceGroup

FetchZonalInstanceGroup queries GCP to return a new instance of the Regional Instance Group type

func FetchZonalInstanceGroupE Uses

func FetchZonalInstanceGroupE(t testing.TestingT, projectID string, zone string, name string) (*ZonalInstanceGroup, error)

FetchZonalInstanceGroup queries GCP to return a new instance of the Regional Instance Group type

func (*ZonalInstanceGroup) GetInstanceIds Uses

func (ig *ZonalInstanceGroup) GetInstanceIds(t testing.TestingT) []string

GetInstanceIds gets the IDs of Instances in the given Instance Group.

func (*ZonalInstanceGroup) GetInstanceIdsE Uses

func (ig *ZonalInstanceGroup) GetInstanceIdsE(t testing.TestingT) ([]string, error)

GetInstanceIdsE gets the IDs of Instances in the given Zonal Instance Group.

func (*ZonalInstanceGroup) GetInstances Uses

func (ig *ZonalInstanceGroup) GetInstances(t testing.TestingT, projectId string) []*Instance

Return a collection of Instance structs from the given Instance Group

func (*ZonalInstanceGroup) GetInstancesE Uses

func (ig *ZonalInstanceGroup) GetInstancesE(t testing.TestingT, projectId string) ([]*Instance, error)

Return a collection of Instance structs from the given Instance Group

func (*ZonalInstanceGroup) GetPublicIps Uses

func (ig *ZonalInstanceGroup) GetPublicIps(t testing.TestingT, projectId string) []string

GetPublicIps returns a slice of the public IPs from the given Instance Group

func (*ZonalInstanceGroup) GetPublicIpsE Uses

func (ig *ZonalInstanceGroup) GetPublicIpsE(t testing.TestingT, projectId string) ([]string, error)

GetPublicIpsE returns a slice of the public IPs from the given Instance Group

func (*ZonalInstanceGroup) GetRandomInstance Uses

func (ig *ZonalInstanceGroup) GetRandomInstance(t testing.TestingT) *Instance

getRandomInstance returns a randomly selected Instance from the Regional Instance Group

func (*ZonalInstanceGroup) GetRandomInstanceE Uses

func (ig *ZonalInstanceGroup) GetRandomInstanceE(t testing.TestingT) (*Instance, error)

getRandomInstanceE returns a randomly selected Instance from the Regional Instance Group

Package gcp imports 25 packages (graph) and is imported by 2 packages. Updated 2020-08-24. Refresh now. Tools for package owners.