deploystack

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 42 Imported by: 6

README

DeployStack

GoDoc

This project is to centralize all of the tools and processes to get terminal interfaces for collecting information from users for use with DeployStack.

Authoring

TLDR;

Quick TLDR omitting testing, which you should totally do but for development and whatnot you can just do this.

  1. Clone this project.
  2. Add your main.tf file
  3. Edit the deploystack.json file
  4. Edit the deploystack.txt file

Running ./deploystack install should spin up the goapp and collect the config items the stack needs to run through the deployment

Running ./deploystack uninstall will destory the whole thing.

Details

Authors are required to make or edit 4 files.

  • main.tf
  • deploystack.json
  • deploystack.txt
  • test

The following files need to be included but shoudln't need to be edited at all:

  • deploystack
  • main.go
  • test.yaml
main.tf

This is a standard terraform file with one adjustment for the DeployStack setup. These files should have several import variables setup with the idea that the golang helper will get them from the user.

variable "project_id" {
  type = string
}

variable "project_number" {
  type = string
}

variable "region" {
  type = string
}

variable "zone" {
  type = string
}
deploystack.json

This config will be read by the golang helper to prompt the user to create a tfvars file that will drive the terraform script.

{
  "title": "Basic Title",
  "duration": 5,
  "collect_project": true,
  "collect_region": true,
  "region_type": "functions",
  "region_default": "us-central1",
  "collect_zone": true,
  "hard_settings": {
    "basename": "appprefix"
  },
  "custom_settings": [
    {
      "name": "nodes",
      "description": "Please enter the number of nodes",
      "options": [
				"roles/reviewer|Project Reviewer",
				"roles/owner|Project Owner",
				"roles/vison.reader|Cloud Vision Reader"
		  ],
	  "default" : "roles/owner|Project Owner"
    }
  ],
  "projects": {
    "allow_duplicates": false,
    "items": [
      {
        "variable_name": "project_id",
        "user_prompt": "Choose a project to use for this application",
        "set_as_default": true
      },
      {
        "variable_name": "project_id_2",
        "user_prompt": "Choose a second project to use for this application",
        "set_as_default": false
      }
    ]
  }
}
deploystack.yaml

You can also use a yaml file if you are using the .deploystack folder setup.

title: Basic Title
duration: 5
collect_project: true
collect_region: true
region_type: functions
region_default: us-central1
collect_zone: true
hard_settings:
  basename: appprefix
custom_settings:
- name: nodes
  description: Please enter the number of nodes
  options:
  - roles/reviewer|Project Reviewer
  - roles/owner|Project Owner
  - roles/vison.reader|Cloud Vision Reader
  default: roles/owner|Project Owner
projects:
  allow_duplicates: false
  items:
  - variable_name: project_id
    user_prompt: Choose a project to use for this application
    set_as_default: true
  - variable_name: project_id_2
    user_prompt: Choose a second project to use for this application
    set_as_default: false
DeployStack Config Settings
Name Type Description
title string You know what a title is
duration number An estimate as to how long this installation takes
collect_project boolean Whether or not to walk the user through picking or creating a project.
collect_region boolean Whether or not to walk the user through picking a regions
register_domain boolean Whether or not to walk the user through registering a domain
configure_gce_instance boolean Whether or not to walk the user through configuring a compute engine instance
region_type string Which product to select a region for
Options: compute, run, functions
region_default string The highlighted and default choice for region.
collect_zone string Whether or not to walk the user through picking a zone
hard_settings Hard Settings are for key value pairs to hardset and not get from the user.
"basename":"appprefix"
prepend_project bool Whether or not to prepend the project id to the default value. Useful for resources like buckets that have to have globally unique names.
path_terraform string Path that DeployStack should regard as the terraform folder.
path_messages string Path that DeployStack should look for messages, description and success.
path_scripts string Path that DeployStack should look for scripts that can be injected into DeployStack routine.
custom_settings Documentation Below Custom Settings are collections of settings that we would like to prompt a user for.
projects Documentation Below Projects are a list of projects with settings that will surface the project selector interface for.
Custom Settings Options
Name Type Description
name string The name of the variable
description string The description of the variable to prompt the user with
default string A default value for the variable.
options array An array of options to turn this into a custom select interface
Note Optionally you can pass a | to divide an option into a value and a label like so:
"weirdConfigSetting|User Readable Label"
Projects Settings Options
Name Type Description
allow_duplicates bool Whether or not a user can use the same project multiple times, defaults to false
Project Settings Options
Name Type Description
variable_name string The name of the variable
user_prompt string The description of the variable to prompt the user with
set_as_default string Whether or not to set this as the default project for the user
UI Controls
Header
  "title":"BASICLB",
  "duration":5,
This process will create the following:

	* Frontend - Cloud Run Service 
	* Middleware - Cloud Run Service
	* Backend - Cloud Sql MySQL instance 
	* Cache - Cloud Memorystore
	* Secrets - Cloud Secret Manager

All of these will spin up configured in a 3 tier application that delievers a
TODO app to show all of these pieces working together.  

UI for Project Selector

Project Selector
  "collect_project":true

UI for Project Selector

Region Selector
  "collect_region":true,
  "region_type":"functions",
  "region_default":"us-central1",

UI for Region Selector

Zone Selector
  "collect_zone":true

UI for Zone Selector

Custom Settings - no options
"name":"nodes",
"description":"Please enter the number of nodes",
"default": "3"

UI for Custom Settings with no options

Custom Settings - options
"name":"nodes",
"description":"Please enter the number of nodes",
"default": "3"
"options": ["1", "2", "3"]

UI for Custom Settings with options

Domain Registration
  "register_domain":true

UI for Domain Registration

deploystack.txt

This file allows you to add a formatted description to the configuration to print out to the user. Json files don't do well with newlines.

test

Test is a shell script that tests the individual pieces of the infrastructure and tests the desired state at the end of the install.

There are a few functions in the template test file that will help you run one of these.

  • section_open - a display function that hellps communicate what is going on.
  • section_close - paired with section_open
  • evaltest - take a gcloud command and a desired outcome to make test assertions
# Setup variables here
source globals
get_project_id PROJECT
get_project_number PROJECT_NUMBER $PROJECT
REGION=us-central1
ZONE=us-central1-a
BASENAME=basiclb
SIZE=3

# Make sure that project is hard set
gcloud config set project ${PROJECT}

# spin up terraform with variables plugged in to build the infrastructure
terraform init
terraform apply -auto-approve -var project_id="${PROJECT}" -var project_number="${PROJECT_NUMBER}" -var region="${REGION}" -var zone="${ZONE}" -var basename="${BASENAME}" -var nodes="${SIZE}"

# You might hace to do some editing here to make these tests work
section_open "Test Managed Instance Group"
    evalTest 'gcloud compute instance-groups managed describe $BASENAME-mig --zone $ZONE --format="value(name)"'  $BASENAME-mig

    COUNT=$(gcloud compute instances list --format="value(name)" | grep $BASENAME-mig | wc -l | xargs)

    if [ $COUNT -ne $SIZE ]
    then
        printf "Halting - error: expected $SIZE instances of GCE got $COUNT  \n"
        exit 1
    else
         printf "number of GCE instances is ok \n"
    fi

section_close

# But in a lot of cases we can just use eval test with a gcloud command and a
# desrired result.
section_open "Test Instance Template"
    evalTest 'gcloud compute instance-templates describe $BASENAME-template --format="value(name)"'  $BASENAME-template
section_close

..

# Now run a destroy operation.
terraform destroy -auto-approve -var project_id="${BASENAME}" -var project_number="${PROJECT_NUMBER}" -var region="${REGION}" -var zone="${ZONE}" -var basename="${BASENAME}" -var nodes="${SIZE}"

# Test all of the parts are destroyed
section_open "Test Managed Instance Group doesn't exist"
    evalTest 'gcloud compute instance-groups managed describe $BASENAME-mig --zone $ZONE --format="value(name)"'  "EXPECTERROR"
section_close

printf "$DIVIDER"
printf "CONGRATS!!!!!!! \n"
printf "You got the end the of your test with everything working. \n"
printf "$DIVIDER"

Testing this Repo

In order to test the helper app in this repo, we need to do a fair amount of manipulation of projects and what not. To faciliate that the tests require a Service Account key json file. To faciliate this there is a script in tools/credsfile that will create a service account, give it the right access and service enablements, and export out a key file to use with testing.

This is not an offical Google product.

Documentation

Overview

Package deploystack provides a series of interfaces for getting Google Cloud settings and configurations for use with DeplyStack

Index

Constants

View Source
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

View Source
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")
)
View Source
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 = ""
)
View Source
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

View Source
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

func BillingAccountAttach(project, account string) error

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

func BillingAccountManage() (string, error)

BillingAccountManage either grabs the users only BillingAccount or presents a list of BillingAccounts to select from.

func BuildDivider

func BuildDivider(width int) (string, error)

BuildDivider captures the size of the terminal screen to build a horizontal divider.

func ClearScreen

func ClearScreen()

ClearScreen will clear out a terminal screen.

func CloudBuildTriggerCreate

func CloudBuildTriggerCreate(project string, trigger cloudbuild.BuildTrigger) (*cloudbuild.BuildTrigger, error)

CloudBuildTriggerCreate creates a build trigger in a given project

func CloudBuildTriggerDelete

func CloudBuildTriggerDelete(project string, triggerid string) error

CloudBuildTriggerDelete deletes a build trigger in a given project

func ComputeImageLatestGet

func ComputeImageLatestGet(project, imageproject, imagefamily string) (string, error)

ComputeImageLatestGet retrieves the latest image from a particular family

func ComputeImageList

func ComputeImageList(project, imageproject string) (*compute.ImageList, error)

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

func ComputeRegionList(project string) ([]string, error)

ComputeRegionList will return a list of regions for Compute Engine

func ComputeZoneList

func ComputeZoneList(project, region string) ([]string, error)

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

func DomainIsVerified(project, domain string) (bool, error)

DomainIsVerified checks to see if a given domain belongs to this user

func DomainManage

func DomainManage(s *Stack) (string, error)

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

func FunctionDelete(project, region, name string) error

FunctionDelete deletes a Cloud Function.

func FunctionDeploy

func FunctionDeploy(project, region string, f cloudfunctions.CloudFunction) error

FunctionDeploy deploys a Cloud Function.

func FunctionGenerateSignedURL

func FunctionGenerateSignedURL(project, region string) (string, error)

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

func FunctionRegionList(project string) ([]string, error)

FunctionRegionList will return a list of regions for Cloud Functions

func ImageManage

func ImageManage(project string) (string, error)

ImageManage promps a user to select a disk type.

func JobDelete

func JobDelete(project, region, job string) error

JobDelete deletes a Cloud Scheduler Job

func JobSchedule

func JobSchedule(project, region string, job schedulerpb.Job) error

JobSchedule creates a Cloud Scheduler Job

func MachineTypeManage

func MachineTypeManage(project, zone string) (string, error)

func ProjectCreate

func ProjectCreate(project, parent, parentType string) error

ProjectCreate does the work of actually creating a new project in your GCP account

func ProjectDelete

func ProjectDelete(project string) error

ProjectDelete does the work of actually deleting an existing project in your GCP account

func ProjectExists

func ProjectExists(project string) bool

ProjectExists confirms that a project actually exists

func ProjectGrantIAMRole

func ProjectGrantIAMRole(project, role, principal string) error

ProjectGrantIAMRole grants a given principal a given role in a given project

func ProjectIDGet

func ProjectIDGet() (string, error)

ProjectIDGet gets the currently set default project

func ProjectIDSet

func ProjectIDSet(project string) error

ProjectIDSet sets the currently set default project

func ProjectListWithBillingEnabled

func ProjectListWithBillingEnabled() (map[string]bool, error)

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

func ProjectNumberGet(id string) (string, error)

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

func RegionManage(project, product, defaultValue string) (string, error)

RegionManage promps a user to select a region.

func RegionsList

func RegionsList(project, product string) ([]string, error)

RegionsList will return a list of RegionsList depending on product type

func RunRegionsList

func RunRegionsList(project string) ([]string, error)

RunRegionsList will return a list of regions for Cloud Run

func SecretCreate

func SecretCreate(project, name, payload string) error

SecretCreate creates a secret and populates the lastest version with a payload.

func SecretDelete

func SecretDelete(project, name string) error

SecretDelete deletes a secret

func ServiceAccountCreate

func ServiceAccountCreate(project, username, displayName string) (string, error)

ServiceAccountCreate creates a service account. A little on the nose

func ServiceDisable

func ServiceDisable(project, service string) error

ServiceDisable disables a service in the selected project

func ServiceEnable

func ServiceEnable(project, service string) error

ServiceEnable enable a service in the selected project so that query calls to various lists will work.

func ServiceIsEnabled

func ServiceIsEnabled(project, service string) (bool, error)

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

func StorageBucketCreate(project, bucket string) error

StorageBucketCreate creates a storage buck in Cloud Storage

func StorageObjectCreate

func StorageObjectCreate(project, bucket, path string) (string, error)

StorageObjectCreate creates an object in a particular bucket in Cloud Storage

func ZoneManage

func ZoneManage(project, region string) (string, error)

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

func NewConfigJSON(content []byte) (Config, error)

NewConfigJSON returns a Config object from a file read.

func NewConfigYAML

func NewConfigYAML(content []byte) (Config, error)

NewConfigYAML returns a Config object from a file read.

func (*Config) ComputeName

func (c *Config) ComputeName() error

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

func (Config) Process

func (c Config) Process(s *Stack, output string) error

Process runs through all of the options in a config and collects all of the necessary data from users.

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.

func (*Custom) Collect

func (c *Custom) Collect() error

Collect will collect a value for a Custom from a user

type Customs

type Customs []Custom

Customs are a slice of Custom variables.

func (*Customs) Collect

func (cs *Customs) Collect() error

Collect calls the collect method of all of the Custom variables in the collection in the order in which they were placed there.

func (Customs) Get

func (cs Customs) Get(name string) Custom

Get returns one Custom Variable

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

type GCEInstanceConfig map[string]string

func GCEInstanceManage

func GCEInstanceManage(project, basename string) (GCEInstanceConfig, error)

func (GCEInstanceConfig) Print

func (gce GCEInstanceConfig) Print(title string)

type LabeledValue

type LabeledValue struct {
	Value     string
	Label     string
	IsDefault bool
}

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

func (*LabeledValues) Sort

func (l *LabeledValues) Sort()

Sort orders the LabeledValues by Label

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

func (*Project) Collect

func (p *Project) Collect(projects []ProjectWithBilling, defaultProject string) error

Collect will collect either an exisitng project or create a new one

type ProjectWithBilling

type ProjectWithBilling struct {
	Name           string
	ID             string
	BillingEnabled bool
}

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

func (*Projects) Collect

func (p *Projects) Collect(projects []ProjectWithBilling, defaultProject string) error

Collect calls the collect method of all of the Projects in the collection in the order in which they were placed there.

type Section

type Section struct {
	Title string
}

Section allows for division of tasks in a DeployStack

func NewSection

func NewSection(title string) Section

NewSection creates an initialized section

func (Section) Close

func (s Section) Close()

Close prints out the footer for a Section.

func (Section) Open

func (s Section) Open()

Open prints out the header for a Section.

type Stack

type Stack struct {
	Settings map[string]string
	Config   Config
}

Stack represents the input config and output settings for this DeployStack

func NewStack

func NewStack() Stack

NewStack returns an initialized Stack

func (Stack) AddSetting

func (s Stack) AddSetting(key, value string)

AddSetting stores a setting key/value pair.

func (Stack) DeleteSetting

func (s Stack) DeleteSetting(key string)

DeleteSetting removes a setting value.

func (*Stack) FindAndReadRequired

func (s *Stack) FindAndReadRequired() error

FindAndReadRequired finds and reads in a Config from a json file.

func (Stack) GetSetting

func (s Stack) GetSetting(key string) string

GetSetting returns a setting value.

func (Stack) PrintSettings

func (s Stack) PrintSettings()

PrintSettings prints the settings to the screen

func (*Stack) Process

func (s *Stack) Process(output string) error

Process passes through a process call to the underlying config.

func (Stack) Terraform

func (s Stack) Terraform() string

Terraform returns all of the settings as a Terraform variables format.

func (Stack) TerraformFile

func (s Stack) TerraformFile(filename string) error

TerraformFile exports TFVars format to input file.

Directories

Path Synopsis
cmd
project-only command
config module
dsgithub module
dstester module
gcloud module
gcloudtf module
github module
terraform module
tui module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL