Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Stable zip sha
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo authored and czimergebot committed Jul 31, 2018
1 parent 9aba82f commit 6b3e3ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.2
0.2.0
32 changes: 23 additions & 9 deletions pkg/provider/data_lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"time"
"path"

"github.com/chanzuckerberg/terraform-provider-bless/pkg/util"
"github.com/gobuffalo/packr"
Expand Down Expand Up @@ -145,12 +146,21 @@ func (l *resourceLambda) getBlessConfig(d *schema.ResourceData) (io.Reader, os.F
return buff, fileInfo, errors.Wrap(err, "Could not templetize config")
}

// Create bundles the lambda code and configuration into a zip that can be uploaded to AWS lambda
func (l *resourceLambda) Read(d *schema.ResourceData, meta interface{}) error {
path := d.Get(schemaOutputPath).(string)
outFile, err := os.Create(path)
// archive generates the zip archive
func (l *resourceLambda) archive(d *schema.ResourceData, meta interface{}) error {
outputPath := d.Get(schemaOutputPath).(string)
outputDirectory := path.Dir(outputPath)
if outputDirectory != "" {
if _, err := os.Stat(outputDirectory); err != nil {
if err := os.MkdirAll(outputDirectory, 0755); err != nil {
return errors.Wrapf(err, "Could not create directories %s", outputDirectory)
}
}
}

outFile, err := os.Create(outputPath)
if err != nil {
return errors.Wrapf(err, "Could not open output file at %s", path)
return errors.Wrapf(err, "Could not open output file at %s", outputPath)
}
defer outFile.Close()
writer := zip.NewWriter(outFile)
Expand All @@ -171,17 +181,21 @@ func (l *resourceLambda) Read(d *schema.ResourceData, meta interface{}) error {
return err
}
// Write the config
err = l.writeFileToZip(blessConfig, blessConfigFileInfo, writer, "bless_deploy.cfg")
return l.writeFileToZip(blessConfig, blessConfigFileInfo, writer, "bless_deploy.cfg")
}

// Create bundles the lambda code and configuration into a zip that can be uploaded to AWS lambda
func (l *resourceLambda) Read(d *schema.ResourceData, meta interface{}) error {
outputPath := d.Get(schemaOutputPath).(string)
err := l.archive(d, meta)
if err != nil {
return err
}

// Calculate file hash for tf state
fileHash, err := util.HashFileForState(outFile.Name())
fileHash, err := util.HashFileForState(outputPath)
if err != nil {
return err
}

d.Set(SchemaOutputBase64Sha256, fileHash)
d.SetId(fileHash)
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/data_lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestLambdaCreate(t *testing.T) {
encrypted_password = "bbbb"
service_name = "test"
kmsauth_key_id = "keyID"
output_path = "/tmp/test"
output_path = "/tmp/test.zip"
}
output "output_base64sha256" {
Expand Down

0 comments on commit 6b3e3ad

Please sign in to comment.