Skip to content

Commit

Permalink
Added pubsubConfig and webhookConfig support to the cloud build resou…
Browse files Browse the repository at this point in the history
…rce. (#4931) (#743)

Co-authored-by: Sumit Madan <sumit.madan@pantheon.io>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Sumit Madan <sumit.madan@pantheon.io>
  • Loading branch information
modular-magician and iamsumit authored Jul 9, 2021
1 parent abf2f76 commit 0574d29
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions google/cloudbuild_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ func GetCloudBuildTriggerApiObject(d TerraformResourceData, config *Config) (map
} else if v, ok := d.GetOkExists("github"); !isEmptyValue(reflect.ValueOf(githubProp)) && (ok || !reflect.DeepEqual(v, githubProp)) {
obj["github"] = githubProp
}
pubsubConfigProp, err := expandCloudBuildTriggerPubsubConfig(d.Get("pubsub_config"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("pubsub_config"); !isEmptyValue(reflect.ValueOf(pubsubConfigProp)) && (ok || !reflect.DeepEqual(v, pubsubConfigProp)) {
obj["pubsubConfig"] = pubsubConfigProp
}
webhookConfigProp, err := expandCloudBuildTriggerWebhookConfig(d.Get("webhook_config"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("webhook_config"); !isEmptyValue(reflect.ValueOf(webhookConfigProp)) && (ok || !reflect.DeepEqual(v, webhookConfigProp)) {
obj["webhookConfig"] = webhookConfigProp
}
buildProp, err := expandCloudBuildTriggerBuild(d.Get("build"), d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -419,6 +431,96 @@ func expandCloudBuildTriggerGithubPushTag(v interface{}, d TerraformResourceData
return v, nil
}

func expandCloudBuildTriggerPubsubConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedSubscription, err := expandCloudBuildTriggerPubsubConfigSubscription(original["subscription"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSubscription); val.IsValid() && !isEmptyValue(val) {
transformed["subscription"] = transformedSubscription
}

transformedTopic, err := expandCloudBuildTriggerPubsubConfigTopic(original["topic"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTopic); val.IsValid() && !isEmptyValue(val) {
transformed["topic"] = transformedTopic
}

transformedServiceAccountEmail, err := expandCloudBuildTriggerPubsubConfigServiceAccountEmail(original["service_account_email"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedServiceAccountEmail); val.IsValid() && !isEmptyValue(val) {
transformed["service_account_email"] = transformedServiceAccountEmail
}

transformedState, err := expandCloudBuildTriggerPubsubConfigState(original["state"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedState); val.IsValid() && !isEmptyValue(val) {
transformed["state"] = transformedState
}

return transformed, nil
}

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

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

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

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

func expandCloudBuildTriggerWebhookConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedSecret, err := expandCloudBuildTriggerWebhookConfigSecret(original["secret"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSecret); val.IsValid() && !isEmptyValue(val) {
transformed["secret"] = transformedSecret
}

transformedState, err := expandCloudBuildTriggerWebhookConfigState(original["state"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedState); val.IsValid() && !isEmptyValue(val) {
transformed["state"] = transformedState
}

return transformed, nil
}

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

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

func expandCloudBuildTriggerBuild(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down

0 comments on commit 0574d29

Please sign in to comment.