From 1f40e23c1c18d3bc5c23e6a4e743ae696c8489e6 Mon Sep 17 00:00:00 2001 From: Erik Jansson Date: Thu, 16 Feb 2017 22:18:18 +0100 Subject: [PATCH] provider/aws: Use proper Set for source.Auth in resource_aws_codebuild_project (#11741) * provider/aws: Use proper Set for Source.Auth * Adding auth to source in test --- .../aws/resource_aws_codebuild_project.go | 20 ++++++++++++++++++- .../resource_aws_codebuild_project_test.go | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_codebuild_project.go b/builtin/providers/aws/resource_aws_codebuild_project.go index 0f9bb9be7..9643dffe6 100644 --- a/builtin/providers/aws/resource_aws_codebuild_project.go +++ b/builtin/providers/aws/resource_aws_codebuild_project.go @@ -503,12 +503,17 @@ func flattenAwsCodebuildProjectSource(source *codebuild.ProjectSource) *schema.S F: resourceAwsCodeBuildProjectSourceHash, } + authSet := schema.Set{ + F: resourceAwsCodeBuildProjectSourceAuthHash, + } + sourceConfig := map[string]interface{}{} sourceConfig["type"] = *source.Type if source.Auth != nil { - sourceConfig["auth"] = sourceAuthToMap(source.Auth) + authSet.Add(sourceAuthToMap(source.Auth)) + sourceConfig["auth"] = &authSet } if source.Buildspec != nil { @@ -566,6 +571,19 @@ func resourceAwsCodeBuildProjectSourceHash(v interface{}) int { return hashcode.String(buf.String()) } +func resourceAwsCodeBuildProjectSourceAuthHash(v interface{}) int { + var buf bytes.Buffer + m := v.(map[string]interface{}) + + authType := m["type"].(string) + authResource := m["resource"].(string) + + buf.WriteString(fmt.Sprintf("%s-", authType)) + buf.WriteString(fmt.Sprintf("%s-", authResource)) + + return hashcode.String(buf.String()) +} + func environmentVariablesToMap(environmentVariables []*codebuild.EnvironmentVariable) []map[string]interface{} { envVariables := make([]map[string]interface{}, len(environmentVariables)) diff --git a/builtin/providers/aws/resource_aws_codebuild_project_test.go b/builtin/providers/aws/resource_aws_codebuild_project_test.go index a21fe0f2a..949a6fb29 100644 --- a/builtin/providers/aws/resource_aws_codebuild_project_test.go +++ b/builtin/providers/aws/resource_aws_codebuild_project_test.go @@ -355,6 +355,10 @@ resource "aws_codebuild_project" "foo" { } source { + auth { + type = "OAUTH" + } + type = "GITHUB" location = "https://github.com/mitchellh/packer.git" }