{"modulePath":"github.com/aws-cloudformation/rain","version":"v1.24.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package stackset\n\n## Variables\n\n```go\nvar DeployCmd = \u0026cobra.Command{\n\tUse:   \"deploy \u003ctemplate\u003e [stackset] [flags]\",\n\tShort: \"Deploy a CloudFormation stack set from a local template\",\n\tLong: `Creates or updates a CloudFormation stack set \u003cstackset\u003e from the template file \u003ctemplate\u003e.\nIf you don't specify a stack set name, rain will use the template filename minus its extension.\nIf you do not specify a template file, rain will asume that you want to add a new instance to an existing template,\nIf a template needs to be packaged before it can be deployed, rain will package the template first.\nRain will attempt to create an S3 bucket to store artifacts that it packages and deploys.\nThe bucket's name will be of the format rain-artifacts-\u003cAWS account id\u003e-\u003cAWS region\u003e.\n\nThe config flags can be used to set accounts, regions to operate and tags with parameters to use.\nConfiguration file with extended options can be provided along with '--config' flag in YAML or JSON format (see [example file](https://github.com/aws-cloudformation/rain/blob/main/test/samples/test-config.yaml) for details).\n\nYAML:\n` + \"```\" + `\nParameters:\n\tName: Value\nTags:\n\tName: Value\nStackSet:\n\tdescription: \"test description\"\n\t...\nStackSetInstances:\n\taccounts:\n\t\t- \"123456789123\"\n\tregions:\n\t\t- us-east-1\n\t\t- us-east-2\n\t...\n` + \"```\" + `\n\nAccount(s) and region(s) provided as flags OVERRIDE values from configuration files. Tags and parameters from the configuration file are MERGED with CLI flag values.\n`,\n\tArgs:                  cobra.RangeArgs(1, 2),\n\tDisableFlagsInUseLine: false,\n\tRun: func(cmd *cobra.Command, args []string) {\n\n\t\ttemplateFilePath := args[0]\n\n\t\tstackSetName := createStackSetName(args)\n\n\t\tcliTagFlags := dc.ListToMap(\"tag\", tags)\n\t\tcliParamFlags := dc.ListToMap(\"param\", params)\n\n\t\tconfigData := readConfiguration(configFilePath)\n\n\t\tif delegatedAdmin {\n\t\t\tconfigData.StackSet.CallAs = types.CallAsDelegatedAdmin\n\t\t\tconfigData.StackSetInstances.CallAs = types.CallAsDelegatedAdmin\n\t\t}\n\n\t\tcombineConfigDataWithCliFlags(\u0026configData, cliParamFlags, cliTagFlags, accounts, regions)\n\n\t\tspinner.Push(fmt.Sprintf(\"Checking current status of stack set '%s'\", stackSetName))\n\t\texistingStackSet, err := cfn.GetStackSet(stackSetName, delegatedAdmin)\n\t\tspinner.Pop()\n\t\tisStacksetExists := false\n\t\tif err == nil \u0026\u0026 existingStackSet.Status != types.StackSetStatusDeleted {\n\t\t\tisStacksetExists = true\n\t\t}\n\t\tconfigData.StackSet.StackSetName = stackSetName\n\t\tconfigData.StackSetInstances.StackSetName = stackSetName\n\n\t\tspinner.Push(fmt.Sprintf(\"Preparing template '%s'\", templateFilePath))\n\t\tconfigData.StackSet.Template = deploy.PackageTemplate(templateFilePath, yes)\n\t\tspinner.Pop()\n\n\t\tconfig.Debugln(\"Handling parameters\")\n\t\tconfigData.StackSet.Parameters = buildParameterTypes(configData.StackSet.Template, configData.Parameters, existingStackSet)\n\n\t\tconfig.Debugln(\"Handling tags\")\n\t\tconfigData.StackSet.Tags = dc.MakeTags(configData.Tags)\n\n\t\tif config.Debug {\n\t\t\tfor _, param := range configData.StackSet.Parameters {\n\t\t\t\tval := ptr.ToString(param.ParameterValue)\n\t\t\t\tif ptr.ToBool(param.UsePreviousValue) {\n\t\t\t\t\tval = \"\u003cprevious value\u003e\"\n\t\t\t\t}\n\t\t\t\tconfig.Debugf(\"  %s: %s\", ptr.ToString(param.ParameterKey), val)\n\t\t\t}\n\t\t}\n\n\t\tif isStacksetExists {\n\t\t\tif forceUpdate || console.Confirm(true, \"Stack set already exists. Do you want to update it?\") {\n\t\t\t\tupdateStackSet(configData)\n\t\t\t\tif !ignoreStackInstances {\n\t\t\t\t\taddInstances(configData)\n\t\t\t\t}\n\n\t\t\t} else {\n\t\t\t\tfmt.Println(console.Yellow(\"operation was cancelled by user\"))\n\t\t\t}\n\t\t} else {\n\t\t\tcreateStackSet(configData)\n\t\t}\n\t},\n}\n```\nDeployCmd is the stackset command's entrypoint\n\n```go\nvar LsCmd = \u0026cobra.Command{\n\tUse:                   \"ls \u003cstack set\u003e\",\n\tShort:                 \"List a CloudFormation stack sets in a given region\",\n\tLong:                  \"List a CloudFormation stack sets in a given region. If you specify a stack set name it will show all the stack instances and last 10 operations.\",\n\tArgs:                  cobra.MaximumNArgs(1),\n\tAliases:               []string{\"list\"},\n\tDisableFlagsInUseLine: true,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tif len(args) == 1 {\n\t\t\tdisplayStackSetSummaryWithInstancesAndLast10Operations(args[0])\n\t\t} else {\n\t\t\tvar err error\n\t\t\tregions := []string{aws.Config().Region}\n\n\t\t\tif all {\n\t\t\t\tspinner.Push(\"Fetching region list\")\n\t\t\t\tregions, err = ec2.GetRegions()\n\t\t\t\tif err != nil {\n\t\t\t\t\tpanic(ui.Errorf(err, \"unable to get region list\"))\n\t\t\t\t}\n\t\t\t\tspinner.Pop()\n\t\t\t}\n\n\t\t\torigRegion := aws.Config().Region\n\n\t\t\tfor _, region := range regions {\n\t\t\t\tspinner.Push(fmt.Sprintf(\"Fetching stack sets in %s\", region))\n\t\t\t\taws.SetRegion(region)\n\t\t\t\tstackSets, err := cfn.ListStackSets(delegatedAdmin)\n\t\t\t\tif err != nil {\n\t\t\t\t\tpanic(ui.Errorf(err, \"failed to list stack sets\"))\n\t\t\t\t}\n\t\t\t\tspinner.Pop()\n\n\t\t\t\tif len(stackSets) == 0 \u0026\u0026 all {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tstackSetNames := make(sort.StringSlice, 0)\n\t\t\t\tstackSetMap := make(map[string]types.StackSetSummary)\n\t\t\t\tfor _, stack := range stackSets {\n\t\t\t\t\tif stack.Status != types.StackSetStatusDeleted {\n\t\t\t\t\t\tstackSetNames = append(stackSetNames, *stack.StackSetName)\n\t\t\t\t\t\tstackSetMap[*stack.StackSetName+region] = stack\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsort.Strings(stackSetNames)\n\n\t\t\t\tfmt.Println(console.Yellow(fmt.Sprintf(\"CloudFormation stack sets in %s:\", region)))\n\t\t\t\tfor _, stackSetName := range stackSetNames {\n\t\t\t\t\tout := strings.Builder{}\n\t\t\t\t\tout.WriteString(fmt.Sprintf(\"%s: %s\\n\",\n\t\t\t\t\t\tstackSetName,\n\t\t\t\t\t\tui.ColouriseStatus(string(stackSetMap[stackSetName+region].Status)),\n\t\t\t\t\t))\n\t\t\t\t\tfmt.Println(ui.Indent(\"  \", out.String()))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\taws.SetRegion(origRegion)\n\t\t}\n\n\t\tall = false\n\t},\n}\n```\nLsCmd is the ls command's entrypoint\n\n```go\nvar RmCmd = \u0026cobra.Command{\n\tUse:                   \"rm \u003cstackset\u003e\",\n\tShort:                 \"Delete a CloudFormation stack set and/or its instances.\",\n\tLong:                  \"Delete a CloudFormation stack set \u003cstackset\u003e and/or its instances.\",\n\tArgs:                  cobra.ExactArgs(1),\n\tAliases:               []string{\"delete\", \"remove\"},\n\tDisableFlagsInUseLine: true,\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tstackSetName := args[0]\n\t\tconfig.Debugf(\"Deleting stack set: %s\\n\", stackSetName)\n\n\t\tstackSet, err := cfn.GetStackSet(stackSetName, delegatedAdmin)\n\t\tif err != nil {\n\t\t\tpanic(ui.Errorf(err, \"Could not find stack set '%s'\", stackSetName))\n\t\t} else if stackSet.Status == types.StackSetStatusDeleted {\n\t\t\tpanic(ui.Errorf(err, \"Stack set '%s' is already in DELETED state \", stackSetName))\n\t\t}\n\n\t\tspinner.Push(\"Deleting stack set..\")\n\t\terr = cfn.DeleteStackSet(stackSetName, delegatedAdmin)\n\t\tspinner.Pop()\n\t\tif err != nil {\n\t\t\tvar notEmptyException *types.StackSetNotEmptyException\n\t\t\tif errors.As(err, \u0026notEmptyException) {\n\n\t\t\t\tinstancesOut, instances := getStackInstances(stackSetName)\n\t\t\t\tfmt.Printf(\"%s\", instancesOut)\n\t\t\t\tinputString := console.Ask(\"Select instances number to delete or 0 to delete all. For multiple selects separate with comma:\")\n\n\t\t\t\taccounts, regions, deleteAll := convertInputString(inputString, instances)\n\n\t\t\t\tspinner.Push(\"Deleting stack set instances...\")\n\t\t\t\tif deleteAll {\n\t\t\t\t\terr = cfn.DeleteAllStackSetInstances(stackSetName, !detach, false, delegatedAdmin)\n\t\t\t\t} else {\n\t\t\t\t\terr = cfn.DeleteStackSetInstances(stackSetName, accounts, regions, !detach, false, delegatedAdmin)\n\t\t\t\t}\n\t\t\t\tspinner.Pop()\n\n\t\t\t\tif err != nil {\n\t\t\t\t\tpanic(ui.Errorf(err, \"error while deleting stack set instances \"))\n\t\t\t\t}\n\n\t\t\t\tif deleteAll {\n\t\t\t\t\tspinner.Push(\"Deleting stack set...\")\n\t\t\t\t\terr = cfn.DeleteStackSet(stackSetName, delegatedAdmin)\n\t\t\t\t\tspinner.Pop()\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tpanic(ui.Errorf(err, \"Could not delete stack set '%s'\", stackSetName))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfmt.Println(\"Stack set deletion has been completed.\")\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpanic(ui.Errorf(err, \"Could not delete stack set '%s'\", stackSetName))\n\t\t\t}\n\n\t\t} else {\n\t\t\tfmt.Println(\"Success!\")\n\t\t}\n\n\t},\n}\n```\nRmCmd is the rm command's entrypoint\n\n```go\nvar StackSetCmd = \u0026cobra.Command{\n\tUse:   \"stackset \u003cstack_set command\u003e\",\n\tShort: \"This command manipulates stack sets.\",\n\tLong:  \"This command manipulates stack sets. It has no action if specific stack set command is not added.\",\n}\n```\n\n","path":"github.com/aws-cloudformation/rain/internal/cmd/stackset","name":"stackset","synopsis":"","isRedistributable":true}
