Skip to content

Commit

Permalink
Merge branch 'master' into aws_emr_cluster-importer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored Nov 14, 2018
2 parents 015ae93 + 137cd3c commit 2d2bb36
Show file tree
Hide file tree
Showing 2,008 changed files with 127,017 additions and 149,552 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
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
29 changes: 29 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Deadline": "5m",
"Enable": [
"deadcode",
"errcheck",
"gofmt",
"ineffassign",
"interfacer",
"misspell",
"structcheck",
"unconvert",
"unparam",
"unused",
"varcheck",
"vet"
],
"EnableGC": true,
"Linters": {
"errcheck": {
"Command": "errcheck -abspath {not_tests=-ignoretests} -ignore github.com/hashicorp/terraform/helper/schema:ForceNew|Set -ignore io:Close"
}
},
"Sort": [
"path",
"line"
],
"Vendor": true,
"WarnUnmatchedDirective": true
}
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
- docker
language: go
go:
- 1.9.1
- "1.11.1"

git:
depth: 1
Expand All @@ -15,12 +15,13 @@ install:
# packages that live there.
# See: https://github.com/golang/go/issues/12933
- bash scripts/gogetcookie.sh
- go get github.com/kardianos/govendor
- make tools

script:
- make lint
- make test
- make vendor-status
- make vet
- make website-lint
- make website-test

branches:
Expand Down
425 changes: 407 additions & 18 deletions CHANGELOG.md

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@ test: fmtcheck
go test $(TEST) -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
TF_ACC=1 go test $(TEST) -v -parallel 20 $(TESTARGS) -timeout 120m

fmt:
gofmt -w $(GOFMT_FILES)
@echo "==> Fixing source code with gofmt..."
gofmt -s -w ./$(PKG_NAME)

# Currently required by tf-deploy compile
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.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
Expand All @@ -55,12 +57,16 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-lint:
@echo "==> Checking website against linters..."
@misspell -error -source=text website/

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(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 vet fmt fmtcheck errcheck vendor-status test-compile website website-test
.PHONY: build sweep test testacc fmt fmtcheck lint tools vendor-status test-compile website website-lint website-test

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Terraform Provider
Requirements
------------

- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
- [Go](https://golang.org/doc/install) 1.9 (to build the provider plugin)
- [Terraform](https://www.terraform.io/downloads.html) 0.10+
- [Go](https://golang.org/doc/install) 1.11 (to build the provider plugin)

Building The Provider
---------------------
Expand All @@ -32,12 +32,12 @@ $ 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
---------------------------

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.9+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.

To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.

Expand Down
4 changes: 2 additions & 2 deletions aws/auth_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,11 @@ var ec2metadata_instanceIdEndpoint = &endpoint{
}

var ec2metadata_securityCredentialsEndpoints = []*endpoint{
&endpoint{
{
Uri: "/latest/meta-data/iam/security-credentials/",
Body: "test_role",
},
&endpoint{
{
Uri: "/latest/meta-data/iam/security-credentials/test_role",
Body: "{\"Code\":\"Success\",\"LastUpdated\":\"2015-12-11T17:17:25Z\",\"Type\":\"AWS-HMAC\",\"AccessKeyId\":\"somekey\",\"SecretAccessKey\":\"somesecret\",\"Token\":\"sometoken\"}",
},
Expand Down
44 changes: 7 additions & 37 deletions aws/autoscaling_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func autoscalingTagSchema() *schema.Schema {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": &schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
},

"value": &schema.Schema{
"value": {
Type: schema.TypeString,
Required: true,
},

"propagate_at_launch": &schema.Schema{
"propagate_at_launch": {
Type: schema.TypeBool,
Required: true,
},
Expand Down 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 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
}
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
Loading

0 comments on commit 2d2bb36

Please sign in to comment.