Documentation
¶
Index ¶
- Constants
- func CreateSchematicTar(projectPath string, includePatterns *[]string) (string, error)
- type IamAuthenticatorSvcI
- type NetrcCredential
- type SchematicsApiSvcI
- type SchematicsTestService
- func (svc *SchematicsTestService) CreateApplyJob() (*schematics.WorkspaceActivityApplyResult, error)
- func (svc *SchematicsTestService) CreateAuthenticator(ibmcloudApiKey string)
- func (svc *SchematicsTestService) CreateDestroyJob() (*schematics.WorkspaceActivityDestroyResult, error)
- func (svc *SchematicsTestService) CreatePlanJob() (*schematics.WorkspaceActivityPlanResult, error)
- func (svc *SchematicsTestService) CreateTestWorkspace(name string, resourceGroup string, templateFolder string, ...) (*schematics.WorkspaceResponse, error)
- func (svc *SchematicsTestService) DeleteWorkspace() (string, error)
- func (svc *SchematicsTestService) FindLatestWorkspaceJobByName(jobName string) (*schematics.WorkspaceActivity, error)
- func (svc *SchematicsTestService) GetRefreshToken() (string, error)
- func (svc *SchematicsTestService) GetWorkspaceJobDetail(jobID string) (*schematics.WorkspaceActivity, error)
- func (svc *SchematicsTestService) InitializeSchematicsService() error
- func (svc *SchematicsTestService) UpdateTestTemplateVars(vars []TestSchematicTerraformVar) error
- func (svc *SchematicsTestService) UploadTarToWorkspace(tarPath string) error
- func (svc *SchematicsTestService) WaitForFinalJobStatus(jobID string) (string, error)
- type TestSchematicOptions
- func (options *TestSchematicOptions) AddNetrcCredential(hostname string, username string, password string)
- func (options *TestSchematicOptions) AddNetrcCredentialByEnv(hostname string, usernameEnvKey string, passwordEnvKey string) error
- func (options *TestSchematicOptions) AddNetrcCredentialByEnvDefault(hostname string) error
- func (options *TestSchematicOptions) AddWorkspaceEnvVar(key string, value string, hidden bool, secure bool)
- func (options *TestSchematicOptions) AddWorkspaceEnvVarFromLocalEnv(key string, hidden bool, secure bool) error
- func (options *TestSchematicOptions) Clone() (*TestSchematicOptions, error)
- func (options *TestSchematicOptions) RunSchematicTest() error
- type TestSchematicTerraformVar
- type WorkspaceEnvironmentVariable
Constants ¶
const DefaultSchematicsApiURL = "https://schematics.cloud.ibm.com"
const DefaultWaitJobCompleteMinutes = int16(120) // default 2 hrs wait time
const SchematicsJobStatusCompleted = "COMPLETED"
IBM schematics job status
const SchematicsJobStatusCreated = "CREATED"
const SchematicsJobStatusFailed = "FAILED"
const SchematicsJobStatusInProgress = "INPROGRESS"
const SchematicsJobTypeApply = "APPLY"
const SchematicsJobTypeDestroy = "DESTROY"
const SchematicsJobTypePlan = "PLAN"
const SchematicsJobTypeUpload = "TAR_WORKSPACE_UPLOAD"
IBM schematics job types
Variables ¶
This section is empty.
Functions ¶
func CreateSchematicTar ¶
CreateSchematicTar will accept a path to a Terraform project and an array of file patterns to include, and will create a TAR file in a temporary location that contains all of the project's files that match the supplied file patterns. This TAR file can then be uploaded to a Schematics Workspace template. Returns a string of the complete TAR file path and file name. Error is returned if any issues happen while creating TAR file.
Types ¶
type IamAuthenticatorSvcI ¶
type IamAuthenticatorSvcI interface { Authenticate(*http.Request) error AuthenticationType() string RequestToken() (*core.IamTokenServerResponse, error) Validate() error }
interface for external IBMCloud IAM Authenticator api. Can be mocked for tests
type NetrcCredential ¶
type SchematicsApiSvcI ¶
type SchematicsApiSvcI interface { CreateWorkspace(*schematics.CreateWorkspaceOptions) (*schematics.WorkspaceResponse, *core.DetailedResponse, error) UpdateWorkspace(*schematics.UpdateWorkspaceOptions) (*schematics.WorkspaceResponse, *core.DetailedResponse, error) DeleteWorkspace(*schematics.DeleteWorkspaceOptions) (*string, *core.DetailedResponse, error) TemplateRepoUpload(*schematics.TemplateRepoUploadOptions) (*schematics.TemplateRepoTarUploadResponse, *core.DetailedResponse, error) ReplaceWorkspaceInputs(*schematics.ReplaceWorkspaceInputsOptions) (*schematics.UserValues, *core.DetailedResponse, error) ListWorkspaceActivities(*schematics.ListWorkspaceActivitiesOptions) (*schematics.WorkspaceActivities, *core.DetailedResponse, error) GetWorkspaceActivity(*schematics.GetWorkspaceActivityOptions) (*schematics.WorkspaceActivity, *core.DetailedResponse, error) PlanWorkspaceCommand(*schematics.PlanWorkspaceCommandOptions) (*schematics.WorkspaceActivityPlanResult, *core.DetailedResponse, error) ApplyWorkspaceCommand(*schematics.ApplyWorkspaceCommandOptions) (*schematics.WorkspaceActivityApplyResult, *core.DetailedResponse, error) DestroyWorkspaceCommand(*schematics.DestroyWorkspaceCommandOptions) (*schematics.WorkspaceActivityDestroyResult, *core.DetailedResponse, error) }
interface for the external schematics service api. Can be mocked for tests
type SchematicsTestService ¶
type SchematicsTestService struct { SchematicsApiSvc SchematicsApiSvcI // the main schematics service interface ApiAuthenticator IamAuthenticatorSvcI // the authenticator used for schematics api calls WorkspaceID string // workspace ID used for tests TemplateID string // workspace template ID used for tests TestOptions *TestSchematicOptions // additional testing options TerraformTestStarted bool // keeps track of when actual Terraform resource testing has begin, used for proper test teardown logic TerraformResourcesCreated bool // keeps track of when we start deploying resources, used for proper test teardown logic }
main data struct for all schematic test methods
func (*SchematicsTestService) CreateApplyJob ¶
func (svc *SchematicsTestService) CreateApplyJob() (*schematics.WorkspaceActivityApplyResult, error)
CreateApplyJob will initiate a new APPLY action on an existing terraform Schematics Workspace. Will return a result object containing details about the new action.
func (*SchematicsTestService) CreateAuthenticator ¶
func (svc *SchematicsTestService) CreateAuthenticator(ibmcloudApiKey string)
CreateAuthenticator will accept a valid IBM cloud API key, and set a valid Authenticator object that will be used in the external provider service for schematics.
func (*SchematicsTestService) CreateDestroyJob ¶
func (svc *SchematicsTestService) CreateDestroyJob() (*schematics.WorkspaceActivityDestroyResult, error)
CreateDestroyJob will initiate a new DESTROY action on an existing terraform Schematics Workspace. Will return a result object containing details about the new action.
func (*SchematicsTestService) CreatePlanJob ¶
func (svc *SchematicsTestService) CreatePlanJob() (*schematics.WorkspaceActivityPlanResult, error)
CreatePlanJob will initiate a new PLAN action on an existing terraform Schematics Workspace. Will return a result object containing details about the new action.
func (*SchematicsTestService) CreateTestWorkspace ¶
func (svc *SchematicsTestService) CreateTestWorkspace(name string, resourceGroup string, templateFolder string, terraformVersion string, tags []string) (*schematics.WorkspaceResponse, error)
CreateTestWorkspace will create a new IBM Schematics Workspace that will be used for testing.
func (*SchematicsTestService) DeleteWorkspace ¶
func (svc *SchematicsTestService) DeleteWorkspace() (string, error)
DeleteWorkspace will delete the existing workspace created for the test service.
func (*SchematicsTestService) FindLatestWorkspaceJobByName ¶
func (svc *SchematicsTestService) FindLatestWorkspaceJobByName(jobName string) (*schematics.WorkspaceActivity, error)
FindLatestWorkspaceJobByName will find the latest executed job of the type supplied and return data about that job. This can be used to find a job by its type when the jobID is not known. A "NotFound" error will be thrown if there are no existing jobs of the provided type.
func (*SchematicsTestService) GetRefreshToken ¶
func (svc *SchematicsTestService) GetRefreshToken() (string, error)
GetRefreshToken will use a previously established Authenticator to create a new IAM Token object, if existing is not valid, and return the refresh token propery from the token object.
func (*SchematicsTestService) GetWorkspaceJobDetail ¶
func (svc *SchematicsTestService) GetWorkspaceJobDetail(jobID string) (*schematics.WorkspaceActivity, error)
GetWorkspaceJobDetail will return a data structure with full details about an existing Schematics Workspace activity for the given Job ID.
func (*SchematicsTestService) InitializeSchematicsService ¶
func (svc *SchematicsTestService) InitializeSchematicsService() error
InitializeSchematicsService will initialize the external service object for schematicsv1 and assign it to a property of the receiver for later use.
func (*SchematicsTestService) UpdateTestTemplateVars ¶
func (svc *SchematicsTestService) UpdateTestTemplateVars(vars []TestSchematicTerraformVar) error
UpdateTestTemplateVars will update an existing Schematics Workspace terraform template with a Variablestore, which will set terraform input variables for test runs.
func (*SchematicsTestService) UploadTarToWorkspace ¶
func (svc *SchematicsTestService) UploadTarToWorkspace(tarPath string) error
UploadTarToWorkspace will accept a file path for an existing TAR file, containing files for a Terraform test case, and upload it to an existing Schematics Workspace.
func (*SchematicsTestService) WaitForFinalJobStatus ¶
func (svc *SchematicsTestService) WaitForFinalJobStatus(jobID string) (string, error)
WaitForFinalJobStatus will look up details about the given activity and check the status value. If the status implies that the activity has not completed yet, this function will keep checking the status value until either the activity has finished, or a configured time threshold has been reached. Returns the final status value of the activity when it has finished. Returns an error if the activity does not finish before the configured time threshold.
type TestSchematicOptions ¶
type TestSchematicOptions struct { Testing *testing.T `copier:"-"` // Testing The current test object TarIncludePatterns []string BestRegionYAMLPath string // BestRegionYAMLPath Path to the yaml containing regions and weights DefaultRegion string // DefaultRegion default region if automatic detection fails ResourceGroup string // ResourceGroup IBM Cloud resource group to use Region string // Region to use RequiredEnvironmentVars map[string]string // RequiredEnvironmentVars TerraformVars []TestSchematicTerraformVar // TerraformVars variables to pass to terraform TemplateFolder string // folder that contains terraform template, defaults to "." Tags []string // Tags optional tags to add Prefix string // Prefix to use when creating resources WaitJobCompleteMinutes int16 // number of minutes to wait for schematic job completions SchematicsApiURL string // OPTIONAL: base URL for schematics API DeleteWorkspaceOnFail bool // if there is a failure, should test delete the workspace and logs, default of false TerraformVersion string // OPTIONAL: Schematics terraform version to use for template. If not supplied will be determined from required version in project NetrcSettings []NetrcCredential // array of .netrc credentials that will be set for schematics workspace WorkspaceEnvVars []WorkspaceEnvironmentVariable // array of ENV variables to set inside workspace CloudInfoService cloudinfo.CloudInfoServiceI // OPTIONAL: Supply if you need multiple tests to share info service and data SchematicsApiSvc SchematicsApiSvcI // OPTIONAL: service pointer for interacting with external schematics api // contains filtered or unexported fields }
TestSchematicOptions is the main data struct containing all options related to running a Terraform unit test wihtin IBM Schematics Workspaces
func TestSchematicOptionsDefault ¶
func TestSchematicOptionsDefault(originalOptions *TestSchematicOptions) *TestSchematicOptions
TestSchematicOptionsDefault is a constructor for struct TestSchematicOptions. This function will accept an existing instance of TestSchematicOptions values, and return a new instance of TestSchematicOptions with the original values set along with appropriate default values for any properties that were not set in the original options.
func (*TestSchematicOptions) AddNetrcCredential ¶
func (options *TestSchematicOptions) AddNetrcCredential(hostname string, username string, password string)
AddNetrcCredential is a helper function for TestSchematicOptions that will append a new netrc credential struct to the appropriate array in the options struct
func (*TestSchematicOptions) AddNetrcCredentialByEnv ¶
func (options *TestSchematicOptions) AddNetrcCredentialByEnv(hostname string, usernameEnvKey string, passwordEnvKey string) error
AddNetrcCredential is a helper function for TestSchematicOptions that will append a new netrc credential struct to the appropriate options array, by retrieving the username and password by lookup up supplied environment variable keys. error returned if any keys are missing in local environment
func (*TestSchematicOptions) AddNetrcCredentialByEnvDefault ¶
func (options *TestSchematicOptions) AddNetrcCredentialByEnvDefault(hostname string) error
AddNetrcCredentialByEnvDefault is a helper function for TestSchematicOptions that will append a new netrc credential struct to the appropriate options array, by retrieving the username and password by looking up the default environment variable keys error returned if any keys are missing in local environment
func (*TestSchematicOptions) AddWorkspaceEnvVar ¶
func (options *TestSchematicOptions) AddWorkspaceEnvVar(key string, value string, hidden bool, secure bool)
AddWorkspaceEnvVar is a helper function for TestSchematicOptions that will append a new ENV entry to options that will be added to the workspace during the test
func (*TestSchematicOptions) AddWorkspaceEnvVarFromLocalEnv ¶
func (options *TestSchematicOptions) AddWorkspaceEnvVarFromLocalEnv(key string, hidden bool, secure bool) error
AddWorkspaceEnvVarFromLocalEnv is a helper function for TestSchematicOptions that will append a new ENV entry to options that will be added to the workspace during the test. The value for the environment variable will be queried from the local OS under the same env var key. error returned if the key is not set in local environment.
func (*TestSchematicOptions) Clone ¶
func (options *TestSchematicOptions) Clone() (*TestSchematicOptions, error)
Clone makes a deep copy of most fields on the Options object and returns it.
NOTE: options.SshAgent and options.Logger CANNOT be deep copied (e.g., the SshAgent struct contains channels and listeners that can't be meaningfully copied), so the original values are retained.
func (*TestSchematicOptions) RunSchematicTest ¶
func (options *TestSchematicOptions) RunSchematicTest() error
RunSchematicTest will use the supplied options to run an end-to-end Terraform test of a project in an IBM Cloud Schematics Workspace. This test will include the following steps: 1. create test workspace 2. create and upload tar file of terraform project to workspace 3. configure supplied test variables in workspace 4. run PLAN/APPLY/DESTROY steps on workspace to provision and destroy resources 5. delete the test workspace