Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Kazmierczak committed Dec 12, 2016
2 parents 92017b6 + fa98b59 commit a5fb739
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 51 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ bora requires:

## Roadmap and status
bora is in very early stages of development. Currently it correctly
interprets meta-templates, converts them into CF files, deploys and
terminates stacks. It is not yet able to update stacks correctly.
Upcoming features:
interprets meta-templates, converts them into CF files, deploys (or
updates )and terminates stacks. Upcoming features:

- Stack updates;
- Role assumption/multi-account deployment;
- Automatic lookup of VPCs, AMIs, subnets and SGs by name;
- Tests...
96 changes: 66 additions & 30 deletions cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,63 @@ func deployStack(t string, session *session.Session) error {
TemplateBody: aws.String(t),
}

// updateParams := &cloudformation.UpdateStackInput{
// StackName: aws.String(stackname),
// TemplateBody: aws.String(t),
// }
updateParams := &cloudformation.UpdateStackInput{
StackName: aws.String(stackname),
TemplateBody: aws.String(t),
}

out, err := svc.CreateStack(createParams)
if stackExists(session) {
log.Println("Stack exists, updating...")

if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
log.Fatal("Deploying failed: ", awsErr.Code(), awsErr.Message())
} else {
log.Fatal("Deploying failed ", err)
return err
out, err := svc.UpdateStack(updateParams)

if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
log.Fatal("Updating stack failed: ", awsErr.Code(), awsErr.Message())
} else {
log.Fatal("Updating stack failed ", err)
return err
}
}
}

describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
}
if err := svc.WaitUntilStackCreateComplete(describeStacksInput); err != nil {
// FIXME this works in so far that we wait until the stack is
// completed and capture errors, but it doesn't really tail
// cloudroamtion events.
log.Fatal(err)
describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
}
if err := svc.WaitUntilStackUpdateComplete(describeStacksInput); err != nil {
// FIXME this works in so far that we wait until the stack is
// completed and capture errors, but it doesn't really tail
// cloudroamtion events.
log.Fatal(err)
}

log.Println("Stack update successful:", out)

} else {

out, err := svc.CreateStack(createParams)

if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
log.Fatal("Deploying failed: ", awsErr.Code(), awsErr.Message())
} else {
log.Fatal("Deploying failed ", err)
return err
}
}

describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
}
if err := svc.WaitUntilStackCreateComplete(describeStacksInput); err != nil {
// FIXME this works in so far that we wait until the stack is
// completed and capture errors, but it doesn't really tail
// cloudroamtion events.
log.Fatal(err)
}

log.Println("Deployment successful:", out)
}

log.Println("Deployment successful:", out)
return nil
}

Expand Down Expand Up @@ -81,12 +111,18 @@ func terminateStack(session *session.Session) error {
return nil
}

// func stackExists(session *session.Session) (error, bool) {
// svc := cloudformation.New(session)
//
// describeStacksInput := &cloudformation.DescribeStacksInput{
// StackName: aws.String(stackname),
// }
//
// return nil, false
// }
func stackExists(session *session.Session) bool {
svc := cloudformation.New(session)

describeStacksInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
}

_, err := svc.DescribeStacks(describeStacksInput)

if err == nil {
return true
}

return false
}
23 changes: 12 additions & 11 deletions exampleTemplates/sqsS3Example.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: {{ .accesscontrol }}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
IndexDocument: {{ .indexdocument }}
ErrorDocument: error.html
DeletionPolicy: Retain
Outputs:
WebsiteURL:
Value: !GetAtt S3Bucket.WebsiteURL
Description: URL for the website hosted on S3
S3BucketSecureURL:
Value: !Sub
- https://${Domain}
- Domain: !GetAtt S3Bucket.DomainName
Description: Name of the S3 bucket to hold website content

Outputs:
WebsiteURL:
Value: !GetAtt S3Bucket.WebsiteURL
Description: URL for the website hosted on S3
S3BucketSecureURL:
Value: !Sub
- https://${Domain}
- Domain: !GetAtt S3Bucket.DomainName
Description: Name of the S3 bucket to hold website content
4 changes: 2 additions & 2 deletions exampleTemplates/sqsS3ExampleConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ region: "eu-central-1"
# Required: specify the name of the stack
# (bora will look for a template under templates/
# that matches the stack name
stackname: "test-sqs-thingy"
stackname: "test-thingy"

# Stack-specific variables
# You can define arbitrary keys in here,
Expand All @@ -17,4 +17,4 @@ CF:
Queues:
- QueueName: "pierwsza"
- QueueName: "druga"
accesscontrol: "PublicRead"
indexdocument: "main.html"
4 changes: 0 additions & 4 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"fmt"
"io/ioutil"
"log"
"text/template"
Expand Down Expand Up @@ -37,10 +36,7 @@ func configReader(conf string) {
for _, confvar := range viper.Sub("CF").AllKeys() {
if confvar != "" {
confval := viper.Get("CF." + confvar)
fmt.Println("Var:", confvar)
fmt.Println("Val:", confval)
cfvars[confvar] = confval

}
}
}
Expand Down

0 comments on commit a5fb739

Please sign in to comment.