This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 504835b
Showing
2,101 changed files
with
687,528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
*.dll | ||
*.exe | ||
.DS_Store | ||
example.tf | ||
terraform.tfplan | ||
terraform.tfstate | ||
bin/ | ||
modules-dev/ | ||
/pkg/ | ||
website/.vagrant | ||
website/.bundle | ||
website/build | ||
website/node_modules | ||
.vagrant/ | ||
*.backup | ||
./*.tfstate | ||
.terraform/ | ||
*.log | ||
*.bak | ||
*~ | ||
.*.swp | ||
.idea | ||
*.iml | ||
*.test | ||
*.iml | ||
|
||
website/vendor | ||
|
||
# Test exclusions | ||
!command/test-fixtures/**/*.tfstate | ||
!command/test-fixtures/**/.terraform/ | ||
|
||
# Keep windows files with windows line endings | ||
*.winfile eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 (Unreleased) | ||
|
||
BACKWARDS INCOMPATIBILITIES / NOTES: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
TEST?=$$(go list ./... |grep -v 'vendor') | ||
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) | ||
PKG_NAME=depoplambda | ||
|
||
default: build | ||
|
||
build: fmtcheck | ||
go install | ||
|
||
test: fmtcheck | ||
go test -i $(TEST) || exit 1 | ||
echo $(TEST) | \ | ||
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 | ||
|
||
testacc: fmtcheck | ||
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m | ||
|
||
vet: | ||
@echo "go vet ." | ||
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ | ||
echo ""; \ | ||
echo "Vet found suspicious constructs. Please check the reported constructs"; \ | ||
echo "and fix them if necessary before submitting the code for review."; \ | ||
exit 1; \ | ||
fi | ||
|
||
fmt: | ||
gofmt -w $(GOFMT_FILES) | ||
|
||
fmtcheck: | ||
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" | ||
|
||
errcheck: | ||
@sh -c "'$(CURDIR)/scripts/errcheck.sh'" | ||
|
||
vendor-status: | ||
@govendor status | ||
|
||
test-compile: | ||
@if [ "$(TEST)" = "./..." ]; then \ | ||
echo "ERROR: Set TEST to a specific package. For example,"; \ | ||
echo " make test-compile TEST=./$(PKG_NAME)"; \ | ||
exit 1; \ | ||
fi | ||
go test -c $(TEST) $(TESTARGS) | ||
|
||
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package depoplambda | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
) | ||
|
||
type Config struct { | ||
AWSRegion string | ||
terraformVersion string | ||
} | ||
|
||
type ManifestClient struct { | ||
s3conn *s3.S3 | ||
bucketName string | ||
bucketKey string | ||
} | ||
|
||
func (c *Config) Client() (interface{}, error) { | ||
var client ManifestClient | ||
|
||
awsConfig := &aws.Config{ | ||
Region: aws.String(c.AWSRegion), | ||
} | ||
|
||
awsSession, err := session.NewSession(awsConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client.s3conn = s3.New(awsSession) | ||
|
||
return &client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package depoplambda | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/aws/aws-sdk-go/service/s3/s3manager" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceLambdas() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceLambdasRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"s3_bucket": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"s3_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "lambdas_manifest.json", | ||
}, | ||
"manifests": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Elem: schema.TypeString, | ||
}, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceLambdasRead(d *schema.ResourceData, meta interface{}) error { | ||
s3Client := meta.(*ManifestClient).s3conn | ||
|
||
headObjInput := &s3.HeadObjectInput{ | ||
Bucket: aws.String(d.Get("s3_bucket").(string)), | ||
Key: aws.String(d.Get("s3_key").(string)), | ||
} | ||
|
||
headObjOutput, err := s3Client.HeadObject(headObjInput) | ||
|
||
if err != nil { | ||
if aerr, ok := err.(awserr.Error); ok { | ||
switch aerr.Code() { | ||
case s3.ErrCodeNoSuchKey: | ||
fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error()) | ||
return err | ||
default: | ||
return err | ||
} | ||
} else { | ||
return err | ||
} | ||
} | ||
|
||
d.SetId(aws.StringValue(headObjOutput.ETag)) | ||
|
||
downloader := s3manager.NewDownloaderWithClient(s3Client) | ||
|
||
var buf []byte | ||
result := aws.NewWriteAtBuffer(buf) | ||
|
||
downloadObjInput := &s3.GetObjectInput{ | ||
Bucket: aws.String(d.Get("s3_bucket").(string)), | ||
Key: aws.String(d.Get("s3_key").(string)), | ||
} | ||
|
||
bytes, err := downloader.Download(result, downloadObjInput) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if bytes == 0 { | ||
return fmt.Errorf("downloaded file contained no data") | ||
} | ||
|
||
manifests := make([]map[string]interface{}, 0) | ||
err = json.Unmarshal(result.Bytes(), &manifests) | ||
if err != nil { | ||
return fmt.Errorf("Unable to decode manfiest files: %s", err) | ||
} | ||
|
||
if err := d.Set("manifests", manifests); err != nil { | ||
return fmt.Errorf("Error setting lambda manifests: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package depoplambda | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
resource "github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
// S3 should contain a manifest file with the following | ||
// [{ | ||
// name: "test_lambda" | ||
// schedule: "* * * * *" | ||
// version: "0.1" | ||
// }] | ||
func TestAccLambdaManifests(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccLambdaManifestsConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceLambdaManifests("data.depoplambda_lambdas.lambdas"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceLambdaManifests(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
fmt.Printf("[DEBUG] name: %s\n", name) | ||
|
||
ds, ok := s.RootModule().Resources[name] | ||
|
||
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
|
||
if ds.Primary.ID == "" { | ||
return fmt.Errorf("Manifest data source ID is not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccLambdaManifestsConfig = ` | ||
data "depoplambda_lambdas" "lambdas" { | ||
s3_bucket = "terraform-provider-depoplambda-test" | ||
}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package depoplambda | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
// Provider returns a terraform.ResourceProvider. | ||
func Provider() terraform.ResourceProvider { | ||
provider := &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"aws_region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "us-east-1", | ||
Description: "AWS Region", | ||
}, | ||
}, | ||
DataSourcesMap: map[string]*schema.Resource{ | ||
"depoplambda_lambdas": dataSourceLambdas(), | ||
}, | ||
} | ||
|
||
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) { | ||
return providerConfigure(d, provider.TerraformVersion) | ||
} | ||
|
||
return provider | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) { | ||
config := Config{ | ||
AWSRegion: d.Get("aws_region").(string), | ||
terraformVersion: terraformVersion, | ||
} | ||
return config.Client() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package depoplambda | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
var testAccProviders map[string]terraform.ResourceProvider | ||
var testAccProvider *schema.Provider | ||
|
||
func init() { | ||
testAccProvider = Provider().(*schema.Provider) | ||
testAccProviders = map[string]terraform.ResourceProvider{ | ||
"depoplambda": testAccProvider, | ||
} | ||
} | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := Provider().(*schema.Provider).InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func TestProvider_impl(t *testing.T) { | ||
var _ terraform.ResourceProvider = Provider() | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("AWS_ACCESS_KEY_ID"); v == "" { | ||
t.Fatal("AWS_ACCESS_KEY_ID must be set for acceptance tests") | ||
} | ||
if v := os.Getenv("AWS_SECRET_ACCESS_KEY"); v == "" { | ||
t.Fatal("AWS_SECRET_ACCESS_KEY must be set for acceptance tests") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/depop/terraform-provider-depoplambda | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.25.3 | ||
github.com/hashicorp/terraform-plugin-sdk v1.4.0 | ||
) |
Oops, something went wrong.