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
This commit is contained in:
Erik Jansson 2017-02-16 22:18:18 +01:00 committed by Paul Stack
parent ae6d82fea8
commit 1f40e23c1c
2 changed files with 23 additions and 1 deletions

View File

@ -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))

View File

@ -355,6 +355,10 @@ resource "aws_codebuild_project" "foo" {
}
source {
auth {
type = "OAUTH"
}
type = "GITHUB"
location = "https://github.com/mitchellh/packer.git"
}