Skip to content

Commit

Permalink
Add pubsubConfigs to cloud source repository (#275)
Browse files Browse the repository at this point in the history
Add pubsubConfigs to cloud source repository
  • Loading branch information
c2thorn authored Dec 5, 2019
2 parents 7add153 + 68add40 commit 92ff367
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion google/sourcerepo_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package google

import "reflect"
import (
"reflect"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func GetSourceRepoRepositoryCaiObject(d TerraformResourceData, config *Config) (Asset, error) {
name, err := assetName(d, config, "//sourcerepo.googleapis.com/projects/{{project}}/repos/{{name}}")
Expand Down Expand Up @@ -45,10 +49,49 @@ func GetSourceRepoRepositoryApiObject(d TerraformResourceData, config *Config) (
} else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
pubsubConfigsProp, err := expandSourceRepoRepositoryPubsubConfigs(d.Get("pubsub_configs"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("pubsub_configs"); !isEmptyValue(reflect.ValueOf(pubsubConfigsProp)) && (ok || !reflect.DeepEqual(v, pubsubConfigsProp)) {
obj["pubsubConfigs"] = pubsubConfigsProp
}

return obj, nil
}

func expandSourceRepoRepositoryName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return replaceVars(d, config, "projects/{{project}}/repos/{{name}}")
}

func expandSourceRepoRepositoryPubsubConfigs(v interface{}, d TerraformResourceData, config *Config) (map[string]interface{}, error) {
if v == nil {
return map[string]interface{}{}, nil
}
m := make(map[string]interface{})
for _, raw := range v.(*schema.Set).List() {
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedMessageFormat, err := expandSourceRepoRepositoryPubsubConfigsMessageFormat(original["message_format"], d, config)
if err != nil {
return nil, err
}
transformed["messageFormat"] = transformedMessageFormat
transformedServiceAccountEmail, err := expandSourceRepoRepositoryPubsubConfigsServiceAccountEmail(original["service_account_email"], d, config)
if err != nil {
return nil, err
}
transformed["serviceAccountEmail"] = transformedServiceAccountEmail

m[original["topic"].(string)] = transformed
}
return m, nil
}

func expandSourceRepoRepositoryPubsubConfigsMessageFormat(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandSourceRepoRepositoryPubsubConfigsServiceAccountEmail(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

0 comments on commit 92ff367

Please sign in to comment.