Documentation
¶
Overview ¶
Package deploystack provides a series of interfaces for getting Google Cloud settings and configurations for use with DeplyStack
Index ¶
- Constants
- Variables
- func BillingAccountAttach(project, account string) error
- func BillingAccountList() ([]*cloudbilling.BillingAccount, error)
- func BillingAccountManage() (string, error)
- func BuildDivider(width int) (string, error)
- func ClearScreen()
- func CloudBuildTriggerCreate(project string, trigger cloudbuild.BuildTrigger) (*cloudbuild.BuildTrigger, error)
- func CloudBuildTriggerDelete(project string, triggerid string) error
- func ComputeImageLatestGet(project, imageproject, imagefamily string) (string, error)
- func ComputeImageList(project, imageproject string) (*compute.ImageList, error)
- func ComputeMachineTypeList(project, zone string) (*compute.MachineTypeList, error)
- func ComputeRegionList(project string) ([]string, error)
- func ComputeZoneList(project, region string) ([]string, error)
- func DomainIsAvailable(project, domain string) (*domainspb.RegisterParameters, error)
- func DomainIsVerified(project, domain string) (bool, error)
- func DomainManage(s *Stack) (string, error)
- func DomainRegister(project string, domaininfo *domainspb.RegisterParameters, contact ContactData) error
- func DomainsSearch(project, domain string) ([]*domainspb.RegisterParameters, error)
- func FunctionDelete(project, region, name string) error
- func FunctionDeploy(project, region string, f cloudfunctions.CloudFunction) error
- func FunctionGenerateSignedURL(project, region string) (string, error)
- func FunctionGet(project, region, name string) (*cloudfunctions.CloudFunction, error)
- func FunctionRegionList(project string) ([]string, error)
- func ImageManage(project string) (string, error)
- func JobDelete(project, region, job string) error
- func JobSchedule(project, region string, job schedulerpb.Job) error
- func MachineTypeManage(project, zone string) (string, error)
- func ProjectCreate(project, parent, parentType string) error
- func ProjectDelete(project string) error
- func ProjectExists(project string) bool
- func ProjectGrantIAMRole(project, role, principal string) error
- func ProjectIDGet() (string, error)
- func ProjectIDSet(project string) error
- func ProjectListWithBillingEnabled() (map[string]bool, error)
- func ProjectNumberGet(id string) (string, error)
- func ProjectParentGet(id string) (*cloudresourcemanager.ResourceId, error)
- func RegionManage(project, product, defaultValue string) (string, error)
- func RegionsList(project, product string) ([]string, error)
- func RunRegionsList(project string) ([]string, error)
- func SecretCreate(project, name, payload string) error
- func SecretDelete(project, name string) error
- func ServiceAccountCreate(project, username, displayName string) (string, error)
- func ServiceDisable(project, service string) error
- func ServiceEnable(project, service string) error
- func ServiceIsEnabled(project, service string) (bool, error)
- func Start()
- func StorageBucketCreate(project, bucket string) error
- func StorageObjectCreate(project, bucket, path string) (string, error)
- func ZoneManage(project, region string) (string, error)
- type Config
- type ContactData
- type Custom
- type Customs
- type DomainRegistrarContact
- type GCEInstanceConfig
- type LabeledValue
- type LabeledValues
- func ComputeImageFamilyList(imgs *compute.ImageList) LabeledValues
- func ComputeImageTypeListByFamily(imgs *compute.ImageList, project, family string) LabeledValues
- func ComputeMachineTypeFamilyList(imgs *compute.MachineTypeList) LabeledValues
- func ComputeMachineTypeListByFamily(imgs *compute.MachineTypeList, family string) LabeledValues
- func NewLabeledValues(sl []string, defaultValue string) LabeledValues
- type PostalAddress
- type Project
- type ProjectWithBilling
- type Projects
- type Section
- type Stack
- func (s Stack) AddSetting(key, value string)
- func (s Stack) DeleteSetting(key string)
- func (s *Stack) FindAndReadRequired() error
- func (s Stack) GetSetting(key string) string
- func (s Stack) PrintSettings()
- func (s *Stack) Process(output string) error
- func (s Stack) Terraform() string
- func (s Stack) TerraformFile(filename string) error
Constants ¶
const ( // TERMCYAN is the terminal code for cyan text TERMCYAN = "\033[0;36m" // TERMCYANB is the terminal code for bold cyan text TERMCYANB = "\033[1;36m" // TERMCYANREV is the terminal code for black on cyan text TERMCYANREV = "\u001b[46m" // TERMRED is the terminal code for red text TERMRED = "\033[0;31m" // TERMREDB is the terminal code for bold red text TERMREDB = "\033[1;31m" // TERMREDREV is the terminal code for black on red text TERMREDREV = "\033[41m" // TERMCLEAR is the terminal code for the clear out color text TERMCLEAR = "\033[0m" // TERMCLEARSCREEN is the terminal code for clearning the whole screen. TERMCLEARSCREEN = "\033[2J" // TERMGREY is the terminal code for grey text TERMGREY = "\033[1;30m" // DefaultRegion is the default compute region used in compute calls. DefaultRegion = "us-central1" // DefaultMachineType is the default compute machine type used in compute calls. DefaultMachineType = "n1-standard" // DefaultImageProject is the default project for images used in compute calls. DefaultImageProject = "debian-cloud" // DefaultImageFamily is the default project for images used in compute calls. DefaultImageFamily = "debian-11" // DefaultDiskSize is the default size for making disks for Compute Engine DefaultDiskSize = "200" // DefaultDiskType is the default style of disk DefaultDiskType = "pd-standard" // DefaultInstanceType is the default machine type of compute engine DefaultInstanceType = "n1-standard-1" // HTTPServerTags are the instance tags to open up the instance to be a // http server HTTPServerTags = "[http-server,https-server]" // DefaultZone is the default zone used in compute calls. DefaultZone = "us-central1-a" )
Variables ¶
var ( // ErrorDomainUntenable is returned when a domain isn't available for registration, but // is also not owned by the user. It can't be used in this app ErrorDomainUntenable = fmt.Errorf("domain is not available, and not owned by attempting user") // ErrorDomainUserDeny is returned when an user declines the choice to purchase. ErrorDomainUserDeny = fmt.Errorf("user said no to buying the domain") )
var ( // ErrorCustomNotValidPhoneNumber is the error you get when you fail phone // number validation. ErrorCustomNotValidPhoneNumber = fmt.Errorf("not a valid phone number") // ErrorBillingInvalidAccount is the error you get if you pass in a bad // Billing Account ID ErrorBillingInvalidAccount = fmt.Errorf("not a valid billing account") // ErrorBillingNoPermission is the error you get if the user lacks billing // related permissions ErrorBillingNoPermission = fmt.Errorf("user lacks permission") // ErrorProjectCreateTooLong is an error when you try to create a project // wuth more than 30 characters ErrorProjectCreateTooLong = fmt.Errorf("project_id contains too many characters, limit 30") // ErrorProjectInvalidCharacters is an error when you try and pass bad // characters into a CreateProjectCall ErrorProjectInvalidCharacters = fmt.Errorf("project_id contains invalid characters") // ErrorProjectAlreadyExists is an error when you try and create a project // That already exists ErrorProjectAlreadyExists = fmt.Errorf("project_id already exists") // ErrorProjectDidNotFinish is an error we cannot confirm that project completion actually occured ErrorProjectDidNotFinish = fmt.Errorf("project creation did not complete in a timely manner") // Divider is a text element that draws a horizontal line Divider = "" )
var DiskProjects = LabeledValues{ LabeledValue{Label: "CentOS", Value: "centos-cloud"}, LabeledValue{Label: "Container-Optimized OS (COS)", Value: "cos-cloud"}, LabeledValue{Label: "Debian", Value: "debian-cloud", IsDefault: true}, LabeledValue{Label: "Fedora CoreOS", Value: "fedora-coreos-cloud"}, LabeledValue{Label: "Red Hat Enterprise Linux (RHEL)", Value: "rhel-cloud"}, LabeledValue{Label: "Red Hat Enterprise Linux (RHEL) for SAP", Value: "rhel-sap-cloud"}, LabeledValue{Label: "Rocky Linux", Value: "rocky-linux-cloud"}, LabeledValue{Label: "SQL Server", Value: "windows-sql-cloud"}, LabeledValue{Label: "SUSE Linux Enterprise Server (SLES)", Value: "suse-cloud"}, LabeledValue{Label: "SUSE Linux Enterprise Server (SLES) for SAP", Value: "suse-cloud"}, LabeledValue{Label: "SUSE Linux Enterprise Server (SLES) BYOS", Value: "suse-byos-cloud"}, LabeledValue{Label: "Ubuntu LTS", Value: "ubuntu-os-cloud"}, LabeledValue{Label: "Ubuntu Pro", Value: "ubuntu-os-pro-cloud"}, LabeledValue{Label: "Windows Server", Value: "windows-cloud"}, }
DiskProjects are the list of projects for disk images for Compute Engine
var ( // ErrorServiceNotExistOrNotAllowed occurs when the user running this code doesn't have // permission to enable the service in the project or it's a nonexistent service name. ErrorServiceNotExistOrNotAllowed = fmt.Errorf("Not found or permission denied for service") )
Functions ¶
func BillingAccountAttach ¶
BillingAccountAttach will enable billing in a given project
func BillingAccountList ¶
func BillingAccountList() ([]*cloudbilling.BillingAccount, error)
BillingAccountList gets a list of the billing accounts a user has access to
func BillingAccountManage ¶
BillingAccountManage either grabs the users only BillingAccount or presents a list of BillingAccounts to select from.
func BuildDivider ¶
BuildDivider captures the size of the terminal screen to build a horizontal divider.
func CloudBuildTriggerCreate ¶
func CloudBuildTriggerCreate(project string, trigger cloudbuild.BuildTrigger) (*cloudbuild.BuildTrigger, error)
CloudBuildTriggerCreate creates a build trigger in a given project
func CloudBuildTriggerDelete ¶
CloudBuildTriggerDelete deletes a build trigger in a given project
func ComputeImageLatestGet ¶
ComputeImageLatestGet retrieves the latest image from a particular family
func ComputeImageList ¶
ComputeImageList gets the list of disk images available for a given image project
func ComputeMachineTypeList ¶
func ComputeMachineTypeList(project, zone string) (*compute.MachineTypeList, error)
ComputeMachineTypeList retrieves the list of Machine Types available in a given zone
func ComputeRegionList ¶
ComputeRegionList will return a list of regions for Compute Engine
func ComputeZoneList ¶
ComputeZoneList will return a list of ComputeZoneList in a given region
func DomainIsAvailable ¶
func DomainIsAvailable(project, domain string) (*domainspb.RegisterParameters, error)
DomainIsAvailable checks to see if a given domain is available for registration
func DomainIsVerified ¶
DomainIsVerified checks to see if a given domain belongs to this user
func DomainManage ¶
DomainManage walks a user through the porocess of collecting contact info and registering a domain.
func DomainRegister ¶
func DomainRegister(project string, domaininfo *domainspb.RegisterParameters, contact ContactData) error
DomainRegister handles registring a domain on behalf of the user.
func DomainsSearch ¶
func DomainsSearch(project, domain string) ([]*domainspb.RegisterParameters, error)
DomainsSearch checks the Cloud Domain api for the input domain
func FunctionDelete ¶
FunctionDelete deletes a Cloud Function.
func FunctionDeploy ¶
func FunctionDeploy(project, region string, f cloudfunctions.CloudFunction) error
FunctionDeploy deploys a Cloud Function.
func FunctionGenerateSignedURL ¶
FunctionGenerateSignedURL generates a signed url for use with uploading to Cloud Storage
func FunctionGet ¶
func FunctionGet(project, region, name string) (*cloudfunctions.CloudFunction, error)
FunctionGet gets the details of a Cloud Function.
func FunctionRegionList ¶
FunctionRegionList will return a list of regions for Cloud Functions
func ImageManage ¶
ImageManage promps a user to select a disk type.
func JobSchedule ¶
func JobSchedule(project, region string, job schedulerpb.Job) error
JobSchedule creates a Cloud Scheduler Job
func MachineTypeManage ¶
func ProjectCreate ¶
ProjectCreate does the work of actually creating a new project in your GCP account
func ProjectDelete ¶
ProjectDelete does the work of actually deleting an existing project in your GCP account
func ProjectExists ¶
ProjectExists confirms that a project actually exists
func ProjectGrantIAMRole ¶
ProjectGrantIAMRole grants a given principal a given role in a given project
func ProjectIDGet ¶
ProjectIDGet gets the currently set default project
func ProjectIDSet ¶
ProjectIDSet sets the currently set default project
func ProjectListWithBillingEnabled ¶
ProjectListWithBillingEnabled queries the billing accounts a user has access to to generate a list of projects for each billing account. Will hopefully reduce the number of calls made to billing api
func ProjectNumberGet ¶
ProjectNumberGet will get the project_number for the input projectid
func ProjectParentGet ¶
func ProjectParentGet(id string) (*cloudresourcemanager.ResourceId, error)
ProjectParentGet returns the parent of an input project
func RegionManage ¶
RegionManage promps a user to select a region.
func RegionsList ¶
RegionsList will return a list of RegionsList depending on product type
func RunRegionsList ¶
RunRegionsList will return a list of regions for Cloud Run
func SecretCreate ¶
SecretCreate creates a secret and populates the lastest version with a payload.
func ServiceAccountCreate ¶
ServiceAccountCreate creates a service account. A little on the nose
func ServiceDisable ¶
ServiceDisable disables a service in the selected project
func ServiceEnable ¶
ServiceEnable enable a service in the selected project so that query calls to various lists will work.
func ServiceIsEnabled ¶
ServiceIsEnabled checks to see if the existing service is already enabled in the project we are trying to enable it in.
func Start ¶
func Start()
Start presents a little documentation screen which also prevents the user from timing out the request to activate Cloud Shell
func StorageBucketCreate ¶
StorageBucketCreate creates a storage buck in Cloud Storage
func StorageObjectCreate ¶
StorageObjectCreate creates an object in a particular bucket in Cloud Storage
func ZoneManage ¶
ZoneManage promps a user to select a zone.
Types ¶
type Config ¶
type Config struct {
Title string `json:"title" yaml:"title"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Duration int `json:"duration" yaml:"duration"`
Project bool `json:"collect_project" yaml:"collect_project"`
ProjectNumber bool `json:"collect_project_number" yaml:"collect_project_number"`
BillingAccount bool `json:"collect_billing_account" yaml:"collect_billing_account"`
Domain bool `json:"register_domain" yaml:"register_domain"`
Region bool `json:"collect_region" yaml:"collect_region"`
RegionType string `json:"region_type" yaml:"region_type"`
RegionDefault string `json:"region_default" yaml:"region_default"`
Zone bool `json:"collect_zone" yaml:"collect_zone"`
HardSet map[string]string `json:"hard_settings" yaml:"hard_settings"`
CustomSettings []Custom `json:"custom_settings" yaml:"custom_settings"`
ConfigureGCEInstance bool `json:"configure_gce_instance" yaml:"configure_gce_instance"`
DocumentationLink string `json:"documentation_link" yaml:"documentation_link"`
PathTerraform string `json:"path_terraform" yaml:"path_terraform"`
PathMessages string `json:"path_messages" yaml:"path_messages"`
PathScripts string `json:"path_scripts" yaml:"path_scripts"`
Projects Projects `json:"projects" yaml:"projects"`
}
Config represents the settings this app will collect from a user. It should be in a json file. The idea is minimal programming has to be done to setup a DeployStack and export out a tfvars file for terraform part of solution.
func NewConfigJSON ¶
NewConfigJSON returns a Config object from a file read.
func NewConfigYAML ¶
NewConfigYAML returns a Config object from a file read.
func (*Config) ComputeName ¶
ComputeName uses the git repo in the working directory to compute the shortname for the application.
func (Config) PrintHeader ¶
func (c Config) PrintHeader()
PrintHeader prints out the header for a DeployStack
type ContactData ¶
type ContactData struct {
AllContacts DomainRegistrarContact `yaml:"allContacts"`
}
ContactData represents the structure that we need for Registrar Contact Data
func RegistrarContactManage ¶
func RegistrarContactManage(file string) (ContactData, error)
RegistrarContactManage manages collecting domain registraton information from the user
func (ContactData) DomainContact ¶
func (c ContactData) DomainContact() (domainspb.ContactSettings, error)
DomainContact outputs a varible in the format that Domain Registration API needs.
func (ContactData) YAML ¶
func (c ContactData) YAML() (string, error)
YAML outputs the content of this structure into the contact format needed for domain registration
type Custom ¶
type Custom struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Default string `json:"default" yaml:"default"`
Value string `json:"value" yaml:"value"`
Options []string `json:"options" yaml:"options"`
PrependProject bool `json:"prepend_project" yaml:"prepend_project"`
Validation string `json:"validation,omitempty" yaml:"validation,omitempty"`
// contains filtered or unexported fields
}
Custom represents a custom setting that we would like to collect from a user We will collect these settings from the user before continuing.
type Customs ¶
type Customs []Custom
Customs are a slice of Custom variables.
type DomainRegistrarContact ¶
type DomainRegistrarContact struct {
Email string `yaml:"email"`
Phone string `yaml:"phoneNumber"`
PostalAddress PostalAddress `yaml:"postalAddress"`
}
DomainRegistrarContact represents the data required to register a domain with a public registrar.
type GCEInstanceConfig ¶
func GCEInstanceManage ¶
func GCEInstanceManage(project, basename string) (GCEInstanceConfig, error)
func (GCEInstanceConfig) Print ¶
func (gce GCEInstanceConfig) Print(title string)
type LabeledValue ¶
LabeledValue is a struct that contains a label/value pair
func NewLabeledValue ¶
func NewLabeledValue(s string) LabeledValue
NewLabeledValue takes a string and converts it to a LabeledValue. If a | delimiter is present it will split into a different label/value
func (LabeledValue) RenderUI ¶
func (l LabeledValue) RenderUI(index, width int) string
RenderUI creates a string that will evantually be shown to a user with terminal formatting characters and what not. extracted render function to make unit testing easier
type LabeledValues ¶
type LabeledValues []LabeledValue
LabeledValues is collection of LabledValue structs
func ComputeImageFamilyList ¶
func ComputeImageFamilyList(imgs *compute.ImageList) LabeledValues
ComputeImageFamilyList gets a list of image families
func ComputeImageTypeListByFamily ¶
func ComputeImageTypeListByFamily(imgs *compute.ImageList, project, family string) LabeledValues
ComputeImageTypeListByFamily retrieves a list of iamge types by the family
func ComputeMachineTypeFamilyList ¶
func ComputeMachineTypeFamilyList(imgs *compute.MachineTypeList) LabeledValues
ComputeMachineTypeFamilyList gets the list of machine type families
func ComputeMachineTypeListByFamily ¶
func ComputeMachineTypeListByFamily(imgs *compute.MachineTypeList, family string) LabeledValues
ComputeMachineTypeListByFamily retrieves the list of machine types available for each family
func NewLabeledValues ¶
func NewLabeledValues(sl []string, defaultValue string) LabeledValues
NewLabeledValues takes a slice of strings and returns a list of LabeledValues
func (*LabeledValues) GetDefault ¶
func (l *LabeledValues) GetDefault() LabeledValue
GetDefault returns the deafult value of the LabeledValues list
func (*LabeledValues) LongestLen ¶
func (l *LabeledValues) LongestLen() int
LongestLen returns the length of longest LABEL in the list
func (LabeledValues) RenderListUI ¶
func (l LabeledValues) RenderListUI() string
RenderListUI creates a string that will evantually be shown to a user with terminal formatting characters and what not in a multi column list if there are enough entries extracted render function to make unit testing easier
func (LabeledValues) SelectUI ¶
func (l LabeledValues) SelectUI() LabeledValue
SelectUI handles showing a user the list of values an allowing them to select one from the list
func (*LabeledValues) SetDefault ¶
func (l *LabeledValues) SetDefault(value string)
SetDefault sets the default value of the list
type PostalAddress ¶
type PostalAddress struct {
RegionCode string `yaml:"regionCode"`
PostalCode string `yaml:"postalCode"`
AdministrativeArea string `yaml:"administrativeArea"`
Locality string `yaml:"locality"`
AddressLines []string `yaml:"addressLines"`
Recipients []string `yaml:"recipients"`
}
PostalAddress represents the mail address in a DomainRegistrarContact
type Project ¶
type Project struct {
Name string `json:"variable_name" yaml:"variable_name"`
UserPrompt string `json:"user_prompt" yaml:"user_prompt"`
SetAsDefault bool `json:"set_as_default" yaml:"set_as_default"`
// contains filtered or unexported fields
}
Project represets a GCP project for use in a stack
type ProjectWithBilling ¶
ProjectWithBilling is a project with it's billing status
func ProjectList ¶
func ProjectList() ([]ProjectWithBilling, error)
ProjectList gets a list of the ProjectList a user has access to
func ProjectListWithBilling ¶
func ProjectListWithBilling(p []*cloudresourcemanager.Project) ([]ProjectWithBilling, error)
ProjectListWithBilling gets a list of projects with their billing information
func (ProjectWithBilling) ToLabledValue ¶
func (p ProjectWithBilling) ToLabledValue() LabeledValue
ToLabledValue converts a ProjectWithBilling to a LabeledValue
type Projects ¶
type Projects struct {
Items []Project `json:"items" yaml:"items"`
AllowDuplicates bool `json:"allow_duplicates" yaml:"allow_duplicates"`
}
Projects is a list of projects that we will collect info for
type Section ¶
type Section struct {
Title string
}
Section allows for division of tasks in a DeployStack
type Stack ¶
Stack represents the input config and output settings for this DeployStack
func (Stack) AddSetting ¶
AddSetting stores a setting key/value pair.
func (Stack) DeleteSetting ¶
DeleteSetting removes a setting value.
func (*Stack) FindAndReadRequired ¶
FindAndReadRequired finds and reads in a Config from a json file.
func (Stack) GetSetting ¶
GetSetting returns a setting value.
func (Stack) PrintSettings ¶
func (s Stack) PrintSettings()
PrintSettings prints the settings to the screen
func (Stack) TerraformFile ¶
TerraformFile exports TFVars format to input file.






