Skip to content

Commit cea8cd8

Browse files
Update CustomTargetType resource to include googleCloudBuildRepo type (#10543) (#7325)
[upstream:121ec509180d23b0bdda2f44349261454ada20d0] Signed-off-by: Modular Magician <[email protected]>
1 parent 10a3d1c commit cea8cd8

File tree

4 files changed

+212
-3
lines changed

4 files changed

+212
-3
lines changed

google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type.go

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ Please refer to the field 'effective_annotations' for all of the annotations pre
129129
},
130130
ExactlyOneOf: []string{},
131131
},
132+
"google_cloud_build_repo": {
133+
Type: schema.TypeList,
134+
Optional: true,
135+
Description: `Cloud Build 2nd gen repository containing the Skaffold Config modules.`,
136+
MaxItems: 1,
137+
Elem: &schema.Resource{
138+
Schema: map[string]*schema.Schema{
139+
"repository": {
140+
Type: schema.TypeString,
141+
Required: true,
142+
Description: `Cloud Build 2nd gen repository in the format of 'projects/<project>/locations/<location>/connections/<connection>/repositories/<repository>'.`,
143+
},
144+
"path": {
145+
Type: schema.TypeString,
146+
Optional: true,
147+
Description: `Relative path from the repository root to the Skaffold file.`,
148+
},
149+
"ref": {
150+
Type: schema.TypeString,
151+
Optional: true,
152+
Description: `Branch or tag to use when cloning the repository.`,
153+
},
154+
},
155+
},
156+
ExactlyOneOf: []string{},
157+
},
132158
"google_cloud_storage": {
133159
Type: schema.TypeList,
134160
Optional: true,
@@ -677,9 +703,10 @@ func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModules(v int
677703
continue
678704
}
679705
transformed = append(transformed, map[string]interface{}{
680-
"configs": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesConfigs(original["configs"], d, config),
681-
"git": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGit(original["git"], d, config),
682-
"google_cloud_storage": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudStorage(original["googleCloudStorage"], d, config),
706+
"configs": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesConfigs(original["configs"], d, config),
707+
"git": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGit(original["git"], d, config),
708+
"google_cloud_storage": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudStorage(original["googleCloudStorage"], d, config),
709+
"google_cloud_build_repo": flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepo(original["googleCloudBuildRepo"], d, config),
683710
})
684711
}
685712
return transformed
@@ -740,6 +767,35 @@ func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogle
740767
return v
741768
}
742769

770+
func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepo(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
771+
if v == nil {
772+
return nil
773+
}
774+
original := v.(map[string]interface{})
775+
if len(original) == 0 {
776+
return nil
777+
}
778+
transformed := make(map[string]interface{})
779+
transformed["repository"] =
780+
flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRepository(original["repository"], d, config)
781+
transformed["path"] =
782+
flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoPath(original["path"], d, config)
783+
transformed["ref"] =
784+
flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRef(original["ref"], d, config)
785+
return []interface{}{transformed}
786+
}
787+
func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRepository(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
788+
return v
789+
}
790+
791+
func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoPath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
792+
return v
793+
}
794+
795+
func flattenClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRef(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
796+
return v
797+
}
798+
743799
func flattenClouddeployCustomTargetTypeEffectiveAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
744800
return v
745801
}
@@ -839,6 +895,13 @@ func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModules(v inte
839895
transformed["googleCloudStorage"] = transformedGoogleCloudStorage
840896
}
841897

898+
transformedGoogleCloudBuildRepo, err := expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepo(original["google_cloud_build_repo"], d, config)
899+
if err != nil {
900+
return nil, err
901+
} else if val := reflect.ValueOf(transformedGoogleCloudBuildRepo); val.IsValid() && !tpgresource.IsEmptyValue(val) {
902+
transformed["googleCloudBuildRepo"] = transformedGoogleCloudBuildRepo
903+
}
904+
842905
req = append(req, transformed)
843906
}
844907
return req, nil
@@ -927,6 +990,51 @@ func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleC
927990
return v, nil
928991
}
929992

993+
func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepo(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
994+
l := v.([]interface{})
995+
if len(l) == 0 || l[0] == nil {
996+
return nil, nil
997+
}
998+
raw := l[0]
999+
original := raw.(map[string]interface{})
1000+
transformed := make(map[string]interface{})
1001+
1002+
transformedRepository, err := expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRepository(original["repository"], d, config)
1003+
if err != nil {
1004+
return nil, err
1005+
} else if val := reflect.ValueOf(transformedRepository); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1006+
transformed["repository"] = transformedRepository
1007+
}
1008+
1009+
transformedPath, err := expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoPath(original["path"], d, config)
1010+
if err != nil {
1011+
return nil, err
1012+
} else if val := reflect.ValueOf(transformedPath); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1013+
transformed["path"] = transformedPath
1014+
}
1015+
1016+
transformedRef, err := expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRef(original["ref"], d, config)
1017+
if err != nil {
1018+
return nil, err
1019+
} else if val := reflect.ValueOf(transformedRef); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1020+
transformed["ref"] = transformedRef
1021+
}
1022+
1023+
return transformed, nil
1024+
}
1025+
1026+
func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRepository(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1027+
return v, nil
1028+
}
1029+
1030+
func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoPath(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1031+
return v, nil
1032+
}
1033+
1034+
func expandClouddeployCustomTargetTypeCustomActionsIncludeSkaffoldModulesGoogleCloudBuildRepoRef(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1035+
return v, nil
1036+
}
1037+
9301038
func expandClouddeployCustomTargetTypeEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
9311039
if v == nil {
9321040
return map[string]string{}, nil

google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_generated_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,53 @@ resource "google_clouddeploy_custom_target_type" "custom-target-type" {
170170
`, context)
171171
}
172172

173+
func TestAccClouddeployCustomTargetType_clouddeployCustomTargetTypeGcbRepoSkaffoldModulesExample(t *testing.T) {
174+
t.Parallel()
175+
176+
context := map[string]interface{}{
177+
"random_suffix": acctest.RandString(t, 10),
178+
}
179+
180+
acctest.VcrTest(t, resource.TestCase{
181+
PreCheck: func() { acctest.AccTestPreCheck(t) },
182+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
183+
CheckDestroy: testAccCheckClouddeployCustomTargetTypeDestroyProducer(t),
184+
Steps: []resource.TestStep{
185+
{
186+
Config: testAccClouddeployCustomTargetType_clouddeployCustomTargetTypeGcbRepoSkaffoldModulesExample(context),
187+
},
188+
{
189+
ResourceName: "google_clouddeploy_custom_target_type.custom-target-type",
190+
ImportState: true,
191+
ImportStateVerify: true,
192+
ImportStateVerifyIgnore: []string{"name", "location", "annotations", "labels", "terraform_labels"},
193+
},
194+
},
195+
})
196+
}
197+
198+
func testAccClouddeployCustomTargetType_clouddeployCustomTargetTypeGcbRepoSkaffoldModulesExample(context map[string]interface{}) string {
199+
return acctest.Nprintf(`
200+
resource "google_clouddeploy_custom_target_type" "custom-target-type" {
201+
location = "us-central1"
202+
name = "tf-test-my-custom-target-type%{random_suffix}"
203+
description = "My custom target type"
204+
custom_actions {
205+
render_action = "renderAction"
206+
deploy_action = "deployAction"
207+
include_skaffold_modules {
208+
configs = ["my-config"]
209+
google_cloud_build_repo {
210+
repository = "projects/example/locations/us-central1/connections/git/repositories/example-repo"
211+
path = "configs/skaffold.yaml"
212+
ref = "main"
213+
}
214+
}
215+
}
216+
}
217+
`, context)
218+
}
219+
173220
func testAccCheckClouddeployCustomTargetTypeDestroyProducer(t *testing.T) func(s *terraform.State) error {
174221
return func(s *terraform.State) error {
175222
for name, rs := range s.RootModule().Resources {

google-beta/services/clouddeploy/resource_clouddeploy_custom_target_type_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ resource "google_clouddeploy_custom_target_type" "custom-target-type" {
8282
ref = "main"
8383
}
8484
}
85+
include_skaffold_modules {
86+
configs = ["my-config3"]
87+
google_cloud_build_repo {
88+
repository = "projects/example/locations/us-central1/connections/git/repositories/example-repo"
89+
path = "configs/skaffold.yaml"
90+
ref = "main"
91+
}
92+
}
8593
}
8694
}
8795
`, context)

website/docs/r/clouddeploy_custom_target_type.html.markdown

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,33 @@ resource "google_clouddeploy_custom_target_type" "custom-target-type" {
110110
}
111111
}
112112
```
113+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
114+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=clouddeploy_custom_target_type_gcb_repo_skaffold_modules&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
115+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
116+
</a>
117+
</div>
118+
## Example Usage - Clouddeploy Custom Target Type Gcb Repo Skaffold Modules
119+
120+
121+
```hcl
122+
resource "google_clouddeploy_custom_target_type" "custom-target-type" {
123+
location = "us-central1"
124+
name = "my-custom-target-type"
125+
description = "My custom target type"
126+
custom_actions {
127+
render_action = "renderAction"
128+
deploy_action = "deployAction"
129+
include_skaffold_modules {
130+
configs = ["my-config"]
131+
google_cloud_build_repo {
132+
repository = "projects/example/locations/us-central1/connections/git/repositories/example-repo"
133+
path = "configs/skaffold.yaml"
134+
ref = "main"
135+
}
136+
}
137+
}
138+
}
139+
```
113140

114141
## Argument Reference
115142

@@ -185,6 +212,11 @@ The following arguments are supported:
185212
Cloud Storage bucket containing Skaffold Config modules.
186213
Structure is [documented below](#nested_google_cloud_storage).
187214

215+
* `google_cloud_build_repo` -
216+
(Optional)
217+
Cloud Build 2nd gen repository containing the Skaffold Config modules.
218+
Structure is [documented below](#nested_google_cloud_build_repo).
219+
188220

189221
<a name="nested_git"></a>The `git` block supports:
190222

@@ -210,6 +242,20 @@ The following arguments are supported:
210242
(Optional)
211243
Relative path from the source to the Skaffold file.
212244

245+
<a name="nested_google_cloud_build_repo"></a>The `google_cloud_build_repo` block supports:
246+
247+
* `repository` -
248+
(Required)
249+
Cloud Build 2nd gen repository in the format of 'projects/<project>/locations/<location>/connections/<connection>/repositories/<repository>'.
250+
251+
* `path` -
252+
(Optional)
253+
Relative path from the repository root to the Skaffold file.
254+
255+
* `ref` -
256+
(Optional)
257+
Branch or tag to use when cloning the repository.
258+
213259
## Attributes Reference
214260

215261
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)