Documentation ¶
Index ¶
Constants ¶
const AWS_PREFIX = "AWS::"
const FILE_PATH string = "FilePath"
Variables ¶
var CCDeployCmd = &cobra.Command{ Use: "deploy <template> <name>", Short: "Deploy a local template directly using the Cloud Control API (Experimental!)", Long: `Creates or updates resources directly using Cloud Control API from the template file <template>. You must pass the --experimental (-x) flag to use this command, to acknowledge that it is experimental and likely to be unstable! `, Args: cobra.ExactArgs(2), DisableFlagsInUseLine: true, Run: deploy, }
var CCDriftCmd = &cobra.Command{ Use: "drift <name>", Short: "Compare the state file to the live state of the resources", Long: `When deploying templates with the cc command, a state file is created and stored in the rain assets bucket. This command outputs a diff of that file and the actual state of the resources, according to Cloud Control API. You can then apply the changes by changing the live state, or by modifying the state file. `, Args: cobra.ExactArgs(1), DisableFlagsInUseLine: true, Run: runDrift, }
var CCRmCmd = &cobra.Command{ Use: "rm <name>", Short: "Delete a deployment created by cc deploy (Experimental!)", Long: "Deletes the resources in the cc deploy deployment named <name> and waits for all CloudControl API calls to complete. This is an experimental feature that requires the -x flag to run.", Args: cobra.ExactArgs(1), Aliases: []string{"ccremove", "ccdel", "ccdelete"}, DisableFlagsInUseLine: true, Run: func(cmd *cobra.Command, args []string) { name := args[0] if !Experimental { panic("Please add the --experimental arg to use this feature") } spinner.Push("Fetching deployment status") key := getStateFileKey(name) var state cft.Template bucketName := s3.RainBucket(yes) obj, err := s3.GetObject(bucketName, key) if err != nil { panic(err) } state, err = parse.String(string(obj)) if err != nil { panic(fmt.Errorf("unable to parse state file: %v", err)) } _, stateMap, _ := s11n.GetMapValue(state.Node.Content[0], "State") if stateMap == nil { panic(fmt.Errorf("did not find State in state file")) } lock := "" for i, s := range stateMap.Content { if s.Kind == yaml.ScalarNode && s.Value == "Lock" { lock = stateMap.Content[i+1].Value } } spinner.Pop() if lock != "" { msg := "Unable to remove deployment, found a locked state file" panic(fmt.Errorf("%v:\ns3://%v/%v (%v)", msg, bucketName, key, lock)) } if !yes { if !console.Confirm(false, "Are you sure you want to delete this deployment?") { panic(fmt.Errorf("Deployment removal cancelled: '%s'", name)) } } spinner.StartTimer(fmt.Sprintf("Removing deployment %v", name)) template := cft.Template{Node: node.Clone(state.Node)} rootMap := template.Node.Content[0] _, stateResourceModels, _ := s11n.GetMapValue(stateMap, "ResourceModels") if stateResourceModels == nil { panic("Expected to find State.ResourceModels in the state template") } identifiers := make(map[string]string, 0) for i, v := range stateResourceModels.Content { if i%2 == 0 { _, identifier, _ := s11n.GetMapValue(stateResourceModels.Content[i+1], "Identifier") if identifier != nil { identifiers[v.Value] = identifier.Value } } } config.Debugf("identifiers: %v", identifiers) _, resourceMap, _ := s11n.GetMapValue(rootMap, "Resources") for i, resource := range resourceMap.Content { if i%2 == 0 { if identifier, ok := identifiers[resource.Value]; !ok { panic(fmt.Errorf("unable to find identifier for %v", resource.Value)) } else { r := resourceMap.Content[i+1] s := node.AddMap(r, "State") node.Add(s, "Action", "Delete") node.Add(s, "Identifier", identifier) } } } config.Debugf("About to delete deployment: %v", format.CftToYaml(template)) results, err := DeployTemplate(template) if err != nil { panic(err) } spinner.StopTimer() results.Summarize() fmt.Printf("Deployment %v successfully removed\n", name) spinner.Push("Deleting state file") err = s3.DeleteObject(bucketName, key) if err != nil { panic(fmt.Errorf("Unable to delete state file %v/%v: %v", bucketName, key, err)) } spinner.Pop() }, }
Cmd is the rm command's entrypoint
var CCStateCmd = &cobra.Command{ Use: "state <name>", Short: "Download the state file for a template deployed with cc deploy", Long: `When deploying templates with the cc command, a state file is created and stored in the rain assets bucket. This command outputs the contents of that file. `, Args: cobra.ExactArgs(1), DisableFlagsInUseLine: true, Run: runState, }
var Cmd = &cobra.Command{
Use: "cc <command>",
Short: "Interact with templates using Cloud Control API instead of CloudFormation",
Long: `You must pass the --experimental (-x) flag to use this command, to acknowledge that it is experimental and likely to be unstable!
`,
}
var Experimental bool
Functions ¶
func PackageTemplate ¶
PackageTemplate reads the template and performs any necessary packaging on it before deployment. The rain bucket will be created if it does not already exist.
func Resolve ¶
resolve resolves CloudFormation intrinsic functions
It relies on dependent resources already having been deployed, so that we can query values with CCAPI.
Supported:
Ref Fn::GetAtt Fn::Sub
Not Supported:
Fn::Base64 Fn::Cidr Condition functions Fn::FindInMap Fn::ForEach Fn::GetAZs Fn::ImportValue Fn::Join Fn::Length Fn::Select Fn::Split Fn::ToJsonString Fn::Transform
Types ¶
type DeploymentResults ¶
DeploymentResults captures everything that happened as a result of deployment
func DeployTemplate ¶
func DeployTemplate(template cft.Template) (*DeploymentResults, error)
deployTemplate deploys the CloudFormation template using the Cloud Control API. A failed deployment will result in DeploymentResults.Succeeded = false. A non-nil error is returned when something unexpected caused a failure not related to actually deploying resources, like an invalid template.
func (*DeploymentResults) Summarize ¶
func (results *DeploymentResults) Summarize()
Summarize prints out a summary of deployment results
type Resource ¶
type Resource struct { Name string Type string Node *yaml.Node State ResourceState Message string Identifier string Model string Action diff.ActionType PriorJson string Start time.Time End time.Time }
func NewResource ¶
func NewResource(name string, resourceType string, state ResourceState, node *yaml.Node) *Resource
NewResource creates a new Resource and adds it to the map
type ResourceState ¶
type ResourceState int
const ( Waiting ResourceState = iota Deploying Failed Deployed Canceled )