Skip to content

Commit

Permalink
Merge branch 'master' into dynamodb_table_item_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Jan 18, 2019
2 parents 3cb6a0b + 3f39778 commit 6c2bf3f
Show file tree
Hide file tree
Showing 1,817 changed files with 324,282 additions and 73,007 deletions.
13 changes: 10 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ existing resources, but you still get to implement something completely new.
covering their behavior. See [Writing Acceptance
Tests](#writing-acceptance-tests) below for a detailed guide on how to
approach these.
- [ ] __Naming__: Resources should be named `aws_<service>_<name>` where
`service` is the AWS short service name and `name` is a short, preferably
single word, description of the resource. Use `_` as a separator.
resources. We therefore encourage you to only submit **1 resource at a time**.
- [ ] __Arguments_and_Attributes__: The HCL for arguments and attributes should
mimic the types and structs presented by the AWS API. API arguments should be
converted from `CamelCase` to `camel_case`.
- [ ] __Documentation__: Each resource gets a page in the Terraform
documentation. The [Terraform website][website] source is in this
repo and includes instructions for getting a local copy of the site up and
Expand Down Expand Up @@ -389,7 +396,7 @@ ok github.com/terraform-providers/terraform-provider-aws/aws 55.619s

Terraform has a framework for writing acceptance tests which minimises the
amount of boilerplate code necessary to use common testing patterns. The entry
point to the framework is the `resource.Test()` function.
point to the framework is the `resource.ParallelTest()` function.

Tests are divided into `TestStep`s. Each `TestStep` proceeds by applying some
Terraform configuration using the provider under test, and then verifying that
Expand All @@ -403,14 +410,14 @@ to a single resource. Most tests follow a similar structure.
to running acceptance tests. This is common to all tests exercising a single
provider.

Each `TestStep` is defined in the call to `resource.Test()`. Most assertion
Each `TestStep` is defined in the call to `resource.ParallelTest()`. Most assertion
functions are defined out of band with the tests. This keeps the tests
readable, and allows reuse of assertion functions across different tests of the
same type of resource. The definition of a complete test looks like this:

```go
func TestAccAzureRMPublicIpStatic_update(t *testing.T) {
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/Feature_Request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 🚀 Feature Request
about: I have a suggestion (and might want to implement myself 🙂)!

labels: enhancement
---

<!--- Please keep this note for the community --->
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/Question.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 💬 Question
about: If you have a question, please check out our other community resources!

labels: question
---

Issues on GitHub are intended to be related to bugs or feature requests with provider codebase,
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ website/vendor

# Keep windows files with windows line endings
*.winfile eol=crlf
/.vs
/.vs
node_modules
4 changes: 4 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"Deadline": "5m",
"Enable": [
"deadcode",
"errcheck",
"gofmt",
"gosimple",
"ineffassign",
"interfacer",
"misspell",
"structcheck",
"unconvert",
"unparam",
"unused",
"varcheck",
"vet"
],
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ services:
- docker
language: go
go:
- "1.11"
- "1.11.x"
env:
GOFLAGS=-mod=vendor

git:
depth: 1
Expand All @@ -20,7 +22,6 @@ install:
script:
- make lint
- make test
- make vendor-status
- make website-lint
- make website-test

Expand Down
562 changes: 561 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test: fmtcheck
go test $(TEST) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
TF_ACC=1 go test $(TEST) -v -parallel 20 $(TESTARGS) -timeout 120m

fmt:
@echo "==> Fixing source code with gofmt..."
Expand All @@ -27,17 +27,16 @@ fmt:
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

websitefmtcheck:
@sh -c "'$(CURDIR)/scripts/websitefmtcheck.sh'"

lint:
@echo "==> Checking source code against linters..."
@gometalinter ./$(PKG_NAME)

tools:
go get -u github.com/kardianos/govendor
go get -u github.com/alecthomas/gometalinter
gometalinter --install

vendor-status:
@govendor status
GO111MODULE=off go get -u github.com/alecthomas/gometalinter
GO111MODULE=off gometalinter --install

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
Expand Down Expand Up @@ -65,5 +64,5 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build sweep test testacc fmt fmtcheck lint tools vendor-status test-compile website website-lint website-test
.PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile website website-lint website-test

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ make build

Using the provider
----------------------
If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it.
If you're building the provider, follow the instructions to [install it as a plugin.](https://www.terraform.io/docs/plugins/basics.html#installing-a-plugin) After placing it into your plugins directory, run `terraform init` to initialize it. Documentation about the provider specific configuration options can be found on the [provider's website](https://www.terraform.io/docs/providers/aws/index.html).

Developing the Provider
---------------------------
Expand Down
41 changes: 6 additions & 35 deletions aws/autoscaling_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) e

if d.HasChange("tag") || d.HasChange("tags") {
oraw, nraw := d.GetChange("tag")
o := setToMapByKey(oraw.(*schema.Set), "key")
n := setToMapByKey(nraw.(*schema.Set), "key")
o := setToMapByKey(oraw.(*schema.Set))
n := setToMapByKey(nraw.(*schema.Set))

old, err := autoscalingTagsFromMap(o, resourceID)
if err != nil {
Expand Down Expand Up @@ -248,36 +248,6 @@ func autoscalingTagFromMap(attr map[string]interface{}, resourceID string) (*aut
return t, nil
}

// autoscalingTagsToMap turns the list of tags into a map.
func autoscalingTagsToMap(ts []*autoscaling.Tag) map[string]interface{} {
tags := make(map[string]interface{})
for _, t := range ts {
tag := map[string]interface{}{
"key": *t.Key,
"value": *t.Value,
"propagate_at_launch": *t.PropagateAtLaunch,
}
tags[*t.Key] = tag
}

return tags
}

// autoscalingTagDescriptionsToMap turns the list of tags into a map.
func autoscalingTagDescriptionsToMap(ts *[]*autoscaling.TagDescription) map[string]map[string]interface{} {
tags := make(map[string]map[string]interface{})
for _, t := range *ts {
tag := map[string]interface{}{
"key": *t.Key,
"value": *t.Value,
"propagate_at_launch": *t.PropagateAtLaunch,
}
tags[*t.Key] = tag
}

return tags
}

// autoscalingTagDescriptionsToSlice turns the list of tags into a slice.
func autoscalingTagDescriptionsToSlice(ts []*autoscaling.TagDescription) []map[string]interface{} {
tags := make([]map[string]interface{}, 0, len(ts))
Expand All @@ -292,11 +262,11 @@ func autoscalingTagDescriptionsToSlice(ts []*autoscaling.TagDescription) []map[s
return tags
}

func setToMapByKey(s *schema.Set, key string) map[string]interface{} {
func setToMapByKey(s *schema.Set) map[string]interface{} {
result := make(map[string]interface{})
for _, rawData := range s.List() {
data := rawData.(map[string]interface{})
result[data[key].(string)] = data
result[data["key"].(string)] = data
}

return result
Expand All @@ -308,7 +278,8 @@ func tagIgnoredAutoscaling(t *autoscaling.Tag) bool {
filter := []string{"^aws:"}
for _, v := range filter {
log.Printf("[DEBUG] Matching %v with %v\n", v, *t.Key)
if r, _ := regexp.MatchString(v, *t.Key); r == true {
r, _ := regexp.MatchString(v, *t.Key)
if r {
log.Printf("[DEBUG] Found AWS specific tag %s (val: %s), ignoring.\n", *t.Key, *t.Value)
return true
}
Expand Down
30 changes: 30 additions & 0 deletions aws/autoscaling_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,33 @@ func TestIgnoringTagsAutoscaling(t *testing.T) {
}
}
}

// autoscalingTagsToMap turns the list of tags into a map.
func autoscalingTagsToMap(ts []*autoscaling.Tag) map[string]interface{} {
tags := make(map[string]interface{})
for _, t := range ts {
tag := map[string]interface{}{
"key": *t.Key,
"value": *t.Value,
"propagate_at_launch": *t.PropagateAtLaunch,
}
tags[*t.Key] = tag
}

return tags
}

// autoscalingTagDescriptionsToMap turns the list of tags into a map.
func autoscalingTagDescriptionsToMap(ts *[]*autoscaling.TagDescription) map[string]map[string]interface{} {
tags := make(map[string]map[string]interface{})
for _, t := range *ts {
tag := map[string]interface{}{
"key": *t.Key,
"value": *t.Value,
"propagate_at_launch": *t.PropagateAtLaunch,
}
tags[*t.Key] = tag
}

return tags
}
8 changes: 2 additions & 6 deletions aws/aws_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ func TestMain(m *testing.M) {
// sharedClientForRegion returns a common AWSClient setup needed for the sweeper
// functions for a given region
func sharedClientForRegion(region string) (interface{}, error) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" {
return nil, fmt.Errorf("empty AWS_ACCESS_KEY_ID")
}

if os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
return nil, fmt.Errorf("empty AWS_SECRET_ACCESS_KEY")
if os.Getenv("AWS_PROFILE") == "" && (os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "") {
return nil, fmt.Errorf("must provide environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or environment variable AWS_PROFILE")
}

conf := &Config{
Expand Down
9 changes: 6 additions & 3 deletions aws/awserr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ func isAWSErr(err error, code string, message string) bool {
return false
}

// Returns true if the error matches all these conditions:
// IsAWSErrExtended returns true if the error matches all conditions
// * err is of type awserr.Error
// * Error.Code() matches code
// * Error.Message() contains message
// * Error.OrigErr() contains origErrMessage
func isAWSErrExtended(err error, code string, message string, origErrMessage string) bool {
// Note: This function will be moved out of the aws package in the future.
func IsAWSErrExtended(err error, code string, message string, origErrMessage string) bool {
if !isAWSErr(err, code, message) {
return false
}
Expand All @@ -48,7 +49,9 @@ func retryOnAwsCode(code string, f func() (interface{}, error)) (interface{}, er
return resp, err
}

func retryOnAwsCodes(codes []string, f func() (interface{}, error)) (interface{}, error) {
// RetryOnAwsCodes retries AWS error codes for one minute
// Note: This function will be moved out of the aws package in the future.
func RetryOnAwsCodes(codes []string, f func() (interface{}, error)) (interface{}, error) {
var resp interface{}
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
Expand Down
6 changes: 3 additions & 3 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func expandDistributionConfig(d *schema.ResourceData) *cloudfront.DistributionCo
distributionConfig.CacheBehaviors = expandCacheBehaviorsDeprecated(d.Get("cache_behavior").(*schema.Set))
}
// This sets CallerReference if it's still pending computation (ie: new resource)
if v, ok := d.GetOk("caller_reference"); ok == false {
if v, ok := d.GetOk("caller_reference"); !ok {
distributionConfig.CallerReference = aws.String(time.Now().Format(time.RFC3339Nano))
} else {
distributionConfig.CallerReference = aws.String(v.(string))
Expand Down Expand Up @@ -524,7 +524,7 @@ func lambdaFunctionAssociationHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["event_type"].(string)))
buf.WriteString(fmt.Sprintf("%s", m["lambda_arn"].(string)))
buf.WriteString(m["lambda_arn"].(string))
buf.WriteString(fmt.Sprintf("%t", m["include_body"].(bool)))
return hashcode.String(buf.String())
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ func simpleCopyStruct(src, dst interface{}) {
d := reflect.ValueOf(dst).Elem()

for i := 0; i < s.NumField(); i++ {
if s.Field(i).CanSet() == true {
if s.Field(i).CanSet() {
if s.Field(i).Interface() != nil {
for j := 0; j < d.NumField(); j++ {
if d.Type().Field(j).Name == s.Type().Field(i).Name {
Expand Down
Loading

0 comments on commit 6c2bf3f

Please sign in to comment.