Skip to content

Commit

Permalink
Merge pull request #19 from StarOfService/feature/capabilities
Browse files Browse the repository at this point in the history
Provide possibility to manage CFN capabilities
  • Loading branch information
linki authored Nov 20, 2018
2 parents daaebb8 + 77f88ff commit 03bb40a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ Check your CloudFormation console once more and validate that your stack as well

Argument | Environment variable | Default value | Description
---------|----------------------|---------------|------------
capability | AWS_CAPABILITIES | | Enable specified capabilities for all stacks managed by the operator instance. Current parameter can be used multiple times. For example: `--capability CAPABILITY_NAMED_IAM --capability CAPABILITY_IAM`. Or with a line break when specifying as an environment variable: `AWS_CAPABILITIES=CAPABILITY_IAM$'\n'CAPABILITY_NAMED_IAM`
debug | DEBUG | | Enable debug logging.
dry-run | DRY_RUN | | If true, don't actually do anything.
tag ... | AWS_TAGS | | Default tags which should be applied for all stacks. The format is `--tag=foo=bar --tag=wambo=baz` on the command line or with a line break when specifying as an env var. (e.g. in zsh: `AWS_TAGS="foo=bar"$'\n'"wambo=baz"`)
Expand Down
16 changes: 9 additions & 7 deletions cmd/cloudformation-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ import (
)

var (
namespace string
region string
tags = new(map[string]string)
dryRun bool
debug bool
version = "0.3.0+git"
namespace string
region string
tags = new(map[string]string)
capabilities = []string{}
dryRun bool
debug bool
version = "0.4.0+git"
)

func init() {
kingpin.Flag("namespace", "The Kubernetes namespace to watch").Default("default").Envar("WATCH_NAMESPACE").StringVar(&namespace)
kingpin.Flag("region", "The AWS region to use").Envar("AWS_REGION").StringVar(&region)
kingpin.Flag("capability", "The AWS CloudFormation capability to enable").Envar("AWS_CAPABILITIES").StringsVar(&capabilities)
kingpin.Flag("dry-run", "If true, don't actually do anything.").Envar("DRY_RUN").BoolVar(&dryRun)
kingpin.Flag("debug", "Enable debug logging.").Envar("DEBUG").BoolVar(&debug)

Expand Down Expand Up @@ -61,6 +63,6 @@ func main() {
})

sdk.Watch("cloudformation.linki.space/v1alpha1", "Stack", namespace, 0)
sdk.Handle(stub.NewHandler(client, *tags, dryRun))
sdk.Handle(stub.NewHandler(client, capabilities, *tags, dryRun))
sdk.Run(context.TODO())
}
13 changes: 8 additions & 5 deletions pkg/stub/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ var (
)

type Handler struct {
client cloudformationiface.CloudFormationAPI
defautTags map[string]string
dryRun bool
client cloudformationiface.CloudFormationAPI
capabilities []string
defautTags map[string]string
dryRun bool
}

func NewHandler(client cloudformationiface.CloudFormationAPI, defautTags map[string]string, dryRun bool) handler.Handler {
return &Handler{client: client, defautTags: defautTags, dryRun: dryRun}
func NewHandler(client cloudformationiface.CloudFormationAPI, capabilities []string, defautTags map[string]string, dryRun bool) handler.Handler {
return &Handler{client: client, capabilities: capabilities, defautTags: defautTags, dryRun: dryRun}
}

func (h *Handler) Handle(ctx types.Context, event types.Event) error {
Expand Down Expand Up @@ -83,6 +84,7 @@ func (h *Handler) createStack(stack *v1alpha1.Stack) error {
}

input := &cloudformation.CreateStackInput{
Capabilities: aws.StringSlice(h.capabilities),
StackName: aws.String(stack.Name),
TemplateBody: aws.String(stack.Spec.Template),
Parameters: stackParameters(stack),
Expand All @@ -109,6 +111,7 @@ func (h *Handler) updateStack(stack *v1alpha1.Stack) error {
}

input := &cloudformation.UpdateStackInput{
Capabilities: aws.StringSlice(h.capabilities),
StackName: aws.String(stack.Name),
TemplateBody: aws.String(stack.Spec.Template),
Parameters: stackParameters(stack),
Expand Down

0 comments on commit 03bb40a

Please sign in to comment.