Skip to content

Commit

Permalink
Merge pull request #11 from terraform-providers/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
DrFaust92 authored Nov 14, 2019
2 parents d94bf3f + 22d8c4f commit ccc05a6
Show file tree
Hide file tree
Showing 53 changed files with 2,486 additions and 1,617 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENHANCEMENTS:
* data-source/aws_iam_group: Add `users` attribute [GH-7132]
* resource/aws_apigateway_stage: Add `arn` attribute [GH-10570]
* resource/aws_apigateway_usage_plan: Add `tags` argument and `arn` attribute [GH-10566]
* resource/aws_s3_bucket: Retry reading tags on `NoSuchBucket` errors due to eventual inconsistency [GH-10863]
* resource/aws_waf_rule: Add `arn` attribute [GH-10798]
* resource/aws_waf_rule_group: Add `arn` attribute [GH-10799]

Expand Down
12 changes: 9 additions & 3 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var serviceNames = []string{
"swf",
"transfer",
"waf",
"wafregional",
"workspaces",
}

Expand All @@ -107,6 +108,7 @@ func main() {
"ListTagsInputIdentifierRequiresSlice": ServiceListTagsInputIdentifierRequiresSlice,
"ListTagsInputResourceTypeField": ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": ServiceListTagsOutputTagsField,
"TagPackage": keyvaluetags.ServiceTagPackage,
"Title": strings.Title,
}

Expand Down Expand Up @@ -161,7 +163,7 @@ import (
// The identifier is typically the Amazon Resource Name (ARN), although
// it may also be a different identifier depending on the service.
func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if . | ListTagsInputResourceTypeField }}, resourceType string{{ end }}) (KeyValueTags, error) {
input := &{{ . }}.{{ . | ListTagsFunction }}Input{
input := &{{ . | TagPackage }}.{{ . | ListTagsFunction }}Input{
{{- if . | ListTagsInputIdentifierRequiresSlice }}
{{ . | ListTagsInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
Expand Down Expand Up @@ -302,6 +304,8 @@ func ServiceListTagsInputIdentifierField(serviceName string) string {
return "ResourceId"
case "waf":
return "ResourceARN"
case "wafregional":
return "ResourceARN"
default:
return "ResourceArn"
}
Expand Down Expand Up @@ -330,8 +334,6 @@ func ServiceListTagsInputResourceTypeField(serviceName string) string {
// ServiceListTagsOutputTagsField determines the service tag field.
func ServiceListTagsOutputTagsField(serviceName string) string {
switch serviceName {
case "waf":
return "TagInfoForResource.TagList"
case "cloudhsmv2":
return "TagList"
case "databasemigrationservice":
Expand All @@ -352,6 +354,10 @@ func ServiceListTagsOutputTagsField(serviceName string) string {
return "TagList"
case "ssm":
return "TagList"
case "waf":
return "TagInfoForResource.TagList"
case "wafregional":
return "TagInfoForResource.TagList"
case "workspaces":
return "TagList"
default:
Expand Down
14 changes: 10 additions & 4 deletions aws/internal/keyvaluetags/generators/servicetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"sort"
"strings"
"text/template"

"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

const filename = `service_tags_gen.go`
Expand Down Expand Up @@ -85,6 +87,7 @@ var sliceServiceNames = []string{
"swf",
"transfer",
"waf",
"wafregional",
"workspaces",
}

Expand Down Expand Up @@ -134,6 +137,7 @@ func main() {
SliceServiceNames: sliceServiceNames,
}
templateFuncMap := template.FuncMap{
"TagPackage": keyvaluetags.ServiceTagPackage,
"TagType": ServiceTagType,
"TagTypeKeyField": ServiceTagTypeKeyField,
"TagTypeValueField": ServiceTagTypeValueField,
Expand Down Expand Up @@ -182,8 +186,10 @@ package keyvaluetags
import (
"github.com/aws/aws-sdk-go/aws"
{{- range .SliceServiceNames }}
{{- if eq . (. | TagPackage) }}
"github.com/aws/aws-sdk-go/service/{{ . }}"
{{- end }}
{{- end }}
)
// map[string]*string handling
Expand All @@ -204,11 +210,11 @@ func {{ . | Title }}KeyValueTags(tags map[string]*string) KeyValueTags {
{{- range .SliceServiceNames }}
// {{ . | Title }}Tags returns {{ . }} service tags.
func (tags KeyValueTags) {{ . | Title }}Tags() []*{{ . }}.{{ . | TagType }} {
result := make([]*{{ . }}.{{ . | TagType }}, 0, len(tags))
func (tags KeyValueTags) {{ . | Title }}Tags() []*{{ . | TagPackage }}.{{ . | TagType }} {
result := make([]*{{ . | TagPackage }}.{{ . | TagType }}, 0, len(tags))
for k, v := range tags.Map() {
tag := &{{ . }}.{{ . | TagType }}{
tag := &{{ . | TagPackage }}.{{ . | TagType }}{
{{ . | TagTypeKeyField }}: aws.String(k),
{{ . | TagTypeValueField }}: aws.String(v),
}
Expand All @@ -220,7 +226,7 @@ func (tags KeyValueTags) {{ . | Title }}Tags() []*{{ . }}.{{ . | TagType }} {
}
// {{ . | Title }}KeyValueTags creates KeyValueTags from {{ . }} service tags.
func {{ . | Title }}KeyValueTags(tags []*{{ . }}.{{ . | TagType }}) KeyValueTags {
func {{ . | Title }}KeyValueTags(tags []*{{ . | TagPackage }}.{{ . | TagType }}) KeyValueTags {
m := make(map[string]*string, len(tags))
for _, tag := range tags {
Expand Down
8 changes: 6 additions & 2 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var serviceNames = []string{
"swf",
"transfer",
"waf",
"wafregional",
"workspaces",
}

Expand All @@ -115,6 +116,7 @@ func main() {
"TagInputIdentifierRequiresSlice": ServiceTagInputIdentifierRequiresSlice,
"TagInputResourceTypeField": ServiceTagInputResourceTypeField,
"TagInputTagsField": ServiceTagInputTagsField,
"TagPackage": keyvaluetags.ServiceTagPackage,
"Title": strings.Title,
"UntagFunction": ServiceUntagFunction,
"UntagInputRequiresTagType": ServiceUntagInputRequiresTagType,
Expand Down Expand Up @@ -178,7 +180,7 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
newTags := New(newTagsMap)
if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 {
input := &{{ . }}.{{ . | UntagFunction }}Input{
input := &{{ . | TagPackage }}.{{ . | UntagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
Expand All @@ -202,7 +204,7 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
}
if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 {
input := &{{ . }}.{{ . | TagFunction }}Input{
input := &{{ . | TagPackage }}.{{ . | TagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
Expand Down Expand Up @@ -365,6 +367,8 @@ func ServiceTagInputIdentifierField(serviceName string) string {
return "Arn"
case "waf":
return "ResourceARN"
case "wafregional":
return "ResourceARN"
case "workspaces":
return "ResourceId"
default:
Expand Down
18 changes: 18 additions & 0 deletions aws/internal/keyvaluetags/list_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions aws/internal/keyvaluetags/service_generation_customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import (
"github.com/aws/aws-sdk-go/service/swf"
"github.com/aws/aws-sdk-go/service/transfer"
"github.com/aws/aws-sdk-go/service/waf"
"github.com/aws/aws-sdk-go/service/wafregional"
"github.com/aws/aws-sdk-go/service/workspaces"
)

Expand Down Expand Up @@ -262,6 +263,8 @@ func ServiceClientType(serviceName string) string {
funcType = reflect.TypeOf(transfer.New)
case "waf":
funcType = reflect.TypeOf(waf.New)
case "wafregional":
funcType = reflect.TypeOf(wafregional.New)
case "workspaces":
funcType = reflect.TypeOf(workspaces.New)
default:
Expand All @@ -270,3 +273,12 @@ func ServiceClientType(serviceName string) string {

return funcType.Out(0).String()
}

func ServiceTagPackage(serviceName string) string {
switch serviceName {
case "wafregional":
return "waf"
default:
return serviceName
}
}
27 changes: 27 additions & 0 deletions aws/internal/keyvaluetags/service_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions aws/internal/keyvaluetags/update_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions aws/resource_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,39 @@ func TestAccAWSLambdaFunction_tracingConfig(t *testing.T) {
})
}

// This test is to verify the existing behavior in the Lambda API where the KMS Key ARN
// is not returned if environment variables are not in use. If the API begins saving this
// value and the kms_key_arn check begins failing, the documentation should be updated.
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/6366
func TestAccAWSLambdaFunction_KmsKeyArn_NoEnvironmentVariables(t *testing.T) {
var function1 lambda.GetFunctionOutput

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lambda_function.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaFunctionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaConfigKmsKeyArnNoEnvironmentVariables(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaFunctionExists(resourceName, rName, &function1),
resource.TestCheckResourceAttr(resourceName, "kms_key_arn", ""),
),
ExpectNonEmptyPlan: true,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"filename", "publish"},
},
},
})
}

func TestAccAWSLambdaFunction_Layers(t *testing.T) {
var conf lambda.GetFunctionOutput

Expand Down Expand Up @@ -2192,6 +2225,42 @@ resource "aws_lambda_function" "test" {
`, funcName)
}

func testAccAWSLambdaConfigKmsKeyArnNoEnvironmentVariables(rName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(rName, rName, rName)+`
resource "aws_kms_key" "test" {
description = %[1]q
deletion_window_in_days = 7
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "kms-tf-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
POLICY
}
resource "aws_lambda_function" "test" {
filename = "test-fixtures/lambdatest.zip"
function_name = %[1]q
handler = "exports.example"
kms_key_arn = "${aws_kms_key.test.arn}"
role = "${aws_iam_role.iam_for_lambda.arn}"
runtime = "nodejs8.10"
}
`, rName)
}

func testAccAWSLambdaConfigWithLayers(funcName, layerName, policyName, roleName, sgName string) string {
return fmt.Sprintf(baseAccAWSLambdaConfig(policyName, roleName, sgName)+`
resource "aws_lambda_layer_version" "test" {
Expand Down
Loading

0 comments on commit ccc05a6

Please sign in to comment.