Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmcintosh committed Apr 24, 2018
2 parents 37bfde8 + b693ab0 commit 3a22ef1
Show file tree
Hide file tree
Showing 481 changed files with 65,471 additions and 13,968 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dist: trusty
sudo: false
sudo: required
services:
- docker
language: go
go:
- 1.9.1
Expand All @@ -16,6 +18,7 @@ script:
- make test
- make vendor-status
- make vet
- make website-test

branches:
only:
Expand Down
270 changes: 238 additions & 32 deletions CHANGELOG.md

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SWEEP?=us-east-1,us-west-2
TEST?=./...
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website

default: build

Expand Down Expand Up @@ -46,5 +47,19 @@ test-compile:
fi
go test -c $(TEST) $(TESTARGS)

.PHONY: build sweep test testacc vet fmt fmtcheck errcheck vendor-status test-compile
website:
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 PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=aws

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=aws

.PHONY: build sweep test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test

26 changes: 0 additions & 26 deletions aws/arn.go

This file was deleted.

13 changes: 0 additions & 13 deletions aws/arn_test.go

This file was deleted.

183 changes: 162 additions & 21 deletions aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (p StringPtrSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Used by the aws_cloudfront_distribution Create and Update functions.
func expandDistributionConfig(d *schema.ResourceData) *cloudfront.DistributionConfig {
distributionConfig := &cloudfront.DistributionConfig{
CacheBehaviors: expandCacheBehaviors(d.Get("cache_behavior").(*schema.Set)),
CustomErrorResponses: expandCustomErrorResponses(d.Get("custom_error_response").(*schema.Set)),
DefaultCacheBehavior: expandDefaultCacheBehavior(d.Get("default_cache_behavior").(*schema.Set).List()[0].(map[string]interface{})),
Enabled: aws.Bool(d.Get("enabled").(bool)),
Expand All @@ -51,6 +50,11 @@ func expandDistributionConfig(d *schema.ResourceData) *cloudfront.DistributionCo
Origins: expandOrigins(d.Get("origin").(*schema.Set)),
PriceClass: aws.String(d.Get("price_class").(string)),
}
if v, ok := d.GetOk("ordered_cache_behavior"); ok {
distributionConfig.CacheBehaviors = expandCacheBehaviors(v.([]interface{}))
} else {
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 {
distributionConfig.CallerReference = aws.String(time.Now().Format(time.RFC3339Nano))
Expand Down Expand Up @@ -140,7 +144,12 @@ func flattenDistributionConfig(d *schema.ResourceData, distributionConfig *cloud
}
}
if distributionConfig.CacheBehaviors != nil {
err = d.Set("cache_behavior", flattenCacheBehaviors(distributionConfig.CacheBehaviors))
if _, ok := d.GetOk("ordered_cache_behavior"); ok {
err = d.Set("ordered_cache_behavior", flattenCacheBehaviors(distributionConfig.CacheBehaviors))
} else {
err = d.Set("cache_behavior", flattenCacheBehaviorsDeprecated(distributionConfig.CacheBehaviors))
}

if err != nil {
return err
}
Expand Down Expand Up @@ -178,7 +187,7 @@ func flattenDistributionConfig(d *schema.ResourceData, distributionConfig *cloud
}

func expandDefaultCacheBehavior(m map[string]interface{}) *cloudfront.DefaultCacheBehavior {
cb := expandCacheBehavior(m)
cb := expandCacheBehaviorDeprecated(m)
var dcb cloudfront.DefaultCacheBehavior

simpleCopyStruct(cb, &dcb)
Expand All @@ -190,7 +199,7 @@ func flattenDefaultCacheBehavior(dcb *cloudfront.DefaultCacheBehavior) *schema.S
var cb cloudfront.CacheBehavior

simpleCopyStruct(dcb, &cb)
m = flattenCacheBehavior(&cb)
m = flattenCacheBehaviorDeprecated(&cb)
return schema.NewSet(defaultCacheBehaviorHash, []interface{}{m})
}

Expand All @@ -204,6 +213,9 @@ func defaultCacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["target_origin_id"].(string)))
buf.WriteString(fmt.Sprintf("%d-", forwardedValuesHash(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{}))))
buf.WriteString(fmt.Sprintf("%d-", m["min_ttl"].(int)))
if d, ok := m["field_level_encryption_id"]; ok && d.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", d.(string)))
}
if d, ok := m["trusted_signers"]; ok {
for _, e := range sortInterfaceSlice(d.([]interface{})) {
buf.WriteString(fmt.Sprintf("%s-", e.(string)))
Expand Down Expand Up @@ -243,11 +255,11 @@ func defaultCacheBehaviorHash(v interface{}) int {
return hashcode.String(buf.String())
}

func expandCacheBehaviors(s *schema.Set) *cloudfront.CacheBehaviors {
func expandCacheBehaviorsDeprecated(s *schema.Set) *cloudfront.CacheBehaviors {
var qty int64
var items []*cloudfront.CacheBehavior
for _, v := range s.List() {
items = append(items, expandCacheBehavior(v.(map[string]interface{})))
items = append(items, expandCacheBehaviorDeprecated(v.(map[string]interface{})))
qty++
}
return &cloudfront.CacheBehaviors{
Expand All @@ -256,23 +268,83 @@ func expandCacheBehaviors(s *schema.Set) *cloudfront.CacheBehaviors {
}
}

func flattenCacheBehaviors(cbs *cloudfront.CacheBehaviors) *schema.Set {
func flattenCacheBehaviorsDeprecated(cbs *cloudfront.CacheBehaviors) *schema.Set {
s := []interface{}{}
for _, v := range cbs.Items {
s = append(s, flattenCacheBehavior(v))
s = append(s, flattenCacheBehaviorDeprecated(v))
}
return schema.NewSet(cacheBehaviorHash, s)
}

func expandCacheBehaviors(lst []interface{}) *cloudfront.CacheBehaviors {
var qty int64
var items []*cloudfront.CacheBehavior
for _, v := range lst {
items = append(items, expandCacheBehavior(v.(map[string]interface{})))
qty++
}
return &cloudfront.CacheBehaviors{
Quantity: aws.Int64(qty),
Items: items,
}
}

func flattenCacheBehaviors(cbs *cloudfront.CacheBehaviors) []interface{} {
lst := []interface{}{}
for _, v := range cbs.Items {
lst = append(lst, flattenCacheBehavior(v))
}
return lst
}

// Deprecated.
func expandCacheBehaviorDeprecated(m map[string]interface{}) *cloudfront.CacheBehavior {
cb := &cloudfront.CacheBehavior{
Compress: aws.Bool(m["compress"].(bool)),
FieldLevelEncryptionId: aws.String(m["field_level_encryption_id"].(string)),
ViewerProtocolPolicy: aws.String(m["viewer_protocol_policy"].(string)),
TargetOriginId: aws.String(m["target_origin_id"].(string)),
ForwardedValues: expandForwardedValues(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{})),
DefaultTTL: aws.Int64(int64(m["default_ttl"].(int))),
MaxTTL: aws.Int64(int64(m["max_ttl"].(int))),
MinTTL: aws.Int64(int64(m["min_ttl"].(int))),
}

if v, ok := m["trusted_signers"]; ok {
cb.TrustedSigners = expandTrustedSigners(v.([]interface{}))
} else {
cb.TrustedSigners = expandTrustedSigners([]interface{}{})
}

if v, ok := m["lambda_function_association"]; ok {
cb.LambdaFunctionAssociations = expandLambdaFunctionAssociations(v.(*schema.Set).List())
}

if v, ok := m["smooth_streaming"]; ok {
cb.SmoothStreaming = aws.Bool(v.(bool))
}
if v, ok := m["allowed_methods"]; ok {
cb.AllowedMethods = expandAllowedMethodsDeprecated(v.([]interface{}))
}
if v, ok := m["cached_methods"]; ok {
cb.AllowedMethods.CachedMethods = expandCachedMethodsDeprecated(v.([]interface{}))
}
if v, ok := m["path_pattern"]; ok {
cb.PathPattern = aws.String(v.(string))
}
return cb
}

func expandCacheBehavior(m map[string]interface{}) *cloudfront.CacheBehavior {
cb := &cloudfront.CacheBehavior{
Compress: aws.Bool(m["compress"].(bool)),
ViewerProtocolPolicy: aws.String(m["viewer_protocol_policy"].(string)),
TargetOriginId: aws.String(m["target_origin_id"].(string)),
ForwardedValues: expandForwardedValues(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{})),
DefaultTTL: aws.Int64(int64(m["default_ttl"].(int))),
MaxTTL: aws.Int64(int64(m["max_ttl"].(int))),
MinTTL: aws.Int64(int64(m["min_ttl"].(int))),
Compress: aws.Bool(m["compress"].(bool)),
FieldLevelEncryptionId: aws.String(m["field_level_encryption_id"].(string)),
ViewerProtocolPolicy: aws.String(m["viewer_protocol_policy"].(string)),
TargetOriginId: aws.String(m["target_origin_id"].(string)),
ForwardedValues: expandForwardedValues(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{})),
DefaultTTL: aws.Int64(int64(m["default_ttl"].(int))),
MaxTTL: aws.Int64(int64(m["max_ttl"].(int))),
MinTTL: aws.Int64(int64(m["min_ttl"].(int))),
}

if v, ok := m["trusted_signers"]; ok {
Expand All @@ -289,21 +361,59 @@ func expandCacheBehavior(m map[string]interface{}) *cloudfront.CacheBehavior {
cb.SmoothStreaming = aws.Bool(v.(bool))
}
if v, ok := m["allowed_methods"]; ok {
cb.AllowedMethods = expandAllowedMethods(v.([]interface{}))
cb.AllowedMethods = expandAllowedMethods(v.(*schema.Set))
}
if v, ok := m["cached_methods"]; ok {
cb.AllowedMethods.CachedMethods = expandCachedMethods(v.([]interface{}))
cb.AllowedMethods.CachedMethods = expandCachedMethods(v.(*schema.Set))
}
if v, ok := m["path_pattern"]; ok {
cb.PathPattern = aws.String(v.(string))
}
return cb
}

func flattenCacheBehaviorDeprecated(cb *cloudfront.CacheBehavior) map[string]interface{} {
m := make(map[string]interface{})

m["compress"] = *cb.Compress
m["field_level_encryption_id"] = aws.StringValue(cb.FieldLevelEncryptionId)
m["viewer_protocol_policy"] = *cb.ViewerProtocolPolicy
m["target_origin_id"] = *cb.TargetOriginId
m["forwarded_values"] = schema.NewSet(forwardedValuesHash, []interface{}{flattenForwardedValues(cb.ForwardedValues)})
m["min_ttl"] = int(*cb.MinTTL)

if len(cb.TrustedSigners.Items) > 0 {
m["trusted_signers"] = flattenTrustedSigners(cb.TrustedSigners)
}
if len(cb.LambdaFunctionAssociations.Items) > 0 {
m["lambda_function_association"] = flattenLambdaFunctionAssociations(cb.LambdaFunctionAssociations)
}
if cb.MaxTTL != nil {
m["max_ttl"] = int(*cb.MaxTTL)
}
if cb.SmoothStreaming != nil {
m["smooth_streaming"] = *cb.SmoothStreaming
}
if cb.DefaultTTL != nil {
m["default_ttl"] = int(*cb.DefaultTTL)
}
if cb.AllowedMethods != nil {
m["allowed_methods"] = flattenAllowedMethodsDeprecated(cb.AllowedMethods)
}
if cb.AllowedMethods.CachedMethods != nil {
m["cached_methods"] = flattenCachedMethodsDeprecated(cb.AllowedMethods.CachedMethods)
}
if cb.PathPattern != nil {
m["path_pattern"] = *cb.PathPattern
}
return m
}

func flattenCacheBehavior(cb *cloudfront.CacheBehavior) map[string]interface{} {
m := make(map[string]interface{})

m["compress"] = *cb.Compress
m["field_level_encryption_id"] = aws.StringValue(cb.FieldLevelEncryptionId)
m["viewer_protocol_policy"] = *cb.ViewerProtocolPolicy
m["target_origin_id"] = *cb.TargetOriginId
m["forwarded_values"] = schema.NewSet(forwardedValuesHash, []interface{}{flattenForwardedValues(cb.ForwardedValues)})
Expand Down Expand Up @@ -346,6 +456,9 @@ func cacheBehaviorHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["target_origin_id"].(string)))
buf.WriteString(fmt.Sprintf("%d-", forwardedValuesHash(m["forwarded_values"].(*schema.Set).List()[0].(map[string]interface{}))))
buf.WriteString(fmt.Sprintf("%d-", m["min_ttl"].(int)))
if d, ok := m["field_level_encryption_id"]; ok && d.(string) != "" {
buf.WriteString(fmt.Sprintf("%s-", d.(string)))
}
if d, ok := m["trusted_signers"]; ok {
for _, e := range sortInterfaceSlice(d.([]interface{})) {
buf.WriteString(fmt.Sprintf("%s-", e.(string)))
Expand Down Expand Up @@ -589,28 +702,56 @@ func flattenCookieNames(cn *cloudfront.CookieNames) []interface{} {
return []interface{}{}
}

func expandAllowedMethods(s []interface{}) *cloudfront.AllowedMethods {
func expandAllowedMethods(s *schema.Set) *cloudfront.AllowedMethods {
return &cloudfront.AllowedMethods{
Quantity: aws.Int64(int64(s.Len())),
Items: expandStringList(s.List()),
}
}

func flattenAllowedMethods(am *cloudfront.AllowedMethods) *schema.Set {
if am.Items != nil {
return schema.NewSet(schema.HashString, flattenStringList(am.Items))
}
return nil
}

func expandAllowedMethodsDeprecated(s []interface{}) *cloudfront.AllowedMethods {
return &cloudfront.AllowedMethods{
Quantity: aws.Int64(int64(len(s))),
Items: expandStringList(s),
}
}

func flattenAllowedMethods(am *cloudfront.AllowedMethods) []interface{} {
func flattenAllowedMethodsDeprecated(am *cloudfront.AllowedMethods) []interface{} {
if am.Items != nil {
return flattenStringList(am.Items)
}
return []interface{}{}
}

func expandCachedMethods(s []interface{}) *cloudfront.CachedMethods {
func expandCachedMethods(s *schema.Set) *cloudfront.CachedMethods {
return &cloudfront.CachedMethods{
Quantity: aws.Int64(int64(s.Len())),
Items: expandStringList(s.List()),
}
}

func flattenCachedMethods(cm *cloudfront.CachedMethods) *schema.Set {
if cm.Items != nil {
return schema.NewSet(schema.HashString, flattenStringList(cm.Items))
}
return nil
}

func expandCachedMethodsDeprecated(s []interface{}) *cloudfront.CachedMethods {
return &cloudfront.CachedMethods{
Quantity: aws.Int64(int64(len(s))),
Items: expandStringList(s),
}
}

func flattenCachedMethods(cm *cloudfront.CachedMethods) []interface{} {
func flattenCachedMethodsDeprecated(cm *cloudfront.CachedMethods) []interface{} {
if cm.Items != nil {
return flattenStringList(cm.Items)
}
Expand Down
Loading

0 comments on commit 3a22ef1

Please sign in to comment.