Skip to content

Commit a6e404e

Browse files
eshagoel06amanMahendroo
authored andcommitted
Add support for global application in Apphub (GoogleCloudPlatform#12017)
1 parent e740ddf commit a6e404e

File tree

4 files changed

+92
-7
lines changed

4 files changed

+92
-7
lines changed

mmv1/products/apphub/Application.yaml

+21-4
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,30 @@ async:
4343
path: 'error'
4444
message: 'message'
4545
custom_code:
46+
constants: 'templates/terraform/constants/apphub_application.go.tmpl'
47+
custom_diff:
48+
- 'apphubApplicationCustomizeDiff'
4649
examples:
47-
- name: 'application_basic'
50+
- name: 'apphub_application_basic'
51+
primary_resource_id: 'example'
52+
vars:
53+
application_id: 'example-application'
54+
location: 'us-east1'
55+
scope_type: 'REGIONAL'
56+
test_vars_overrides:
57+
'location': '"us-east1"'
58+
'scope_type': '"REGIONAL"'
59+
- name: 'apphub_application_global_basic'
4860
config_path: 'templates/terraform/examples/apphub_application_basic.tf.tmpl'
4961
primary_resource_id: 'example'
5062
vars:
5163
application_id: 'example-application'
52-
- name: 'application_full'
53-
config_path: 'templates/terraform/examples/apphub_application_full.tf.tmpl'
64+
location: 'global'
65+
scope_type: 'GLOBAL'
66+
test_vars_overrides:
67+
'location': '"global"'
68+
'scope_type': '"GLOBAL"'
69+
- name: 'apphub_application_full'
5470
primary_resource_id: 'example2'
5571
vars:
5672
application_id: 'example-application'
@@ -171,10 +187,11 @@ properties:
171187
properties:
172188
- name: 'type'
173189
type: Enum
174-
description: "Required. Scope Type. \n Possible values:\nREGIONAL"
190+
description: "Required. Scope Type. \n Possible values:\nREGIONAL\nGLOBAL"
175191
required: true
176192
enum_values:
177193
- 'REGIONAL'
194+
- 'GLOBAL'
178195
- name: 'uid'
179196
type: String
180197
description: 'Output only. A universally unique identifier (in UUID4 format) for
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
func apphubApplicationCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
2+
if diff.HasChange("location") || diff.HasChange("scope.0.type") {
3+
location := diff.Get("location")
4+
scope_type := diff.Get("scope.0.type")
5+
6+
if scope_type == "GLOBAL" {
7+
if location != "global" {
8+
return fmt.Errorf("Error validating location %s with %s scope type", location, scope_type)
9+
}
10+
} else {
11+
if location == "global" {
12+
return fmt.Errorf("Error validating location %s with %s scope type", location, scope_type)
13+
}
14+
}
15+
}
16+
return nil
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "google_apphub_application" "{{$.PrimaryResourceId}}" {
2-
location = "us-east1"
2+
location = "{{index $.Vars "location"}}"
33
application_id = "{{index $.Vars "application_id"}}"
44
scope {
5-
type = "REGIONAL"
5+
type = "{{index $.Vars "scope_type"}}"
66
}
77
}

mmv1/third_party/terraform/services/apphub/resource_apphub_application_test.go

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package apphub_test
22

33
import (
4+
"regexp"
45
"testing"
56

67
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -21,7 +22,7 @@ func TestAccApphubApplication_applicationUpdateFull(t *testing.T) {
2122
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
2223
Steps: []resource.TestStep{
2324
{
24-
Config: testAccApphubApplication_applicationFullExample(context),
25+
Config: testAccApphubApplication_apphubApplicationFullExample(context),
2526
},
2627
{
2728
ResourceName: "google_apphub_application.example2",
@@ -208,3 +209,53 @@ resource "google_apphub_application" "example2" {
208209
}
209210
`, context)
210211
}
212+
213+
func TestAccApphubApplication_invalidConfigFails(t *testing.T) {
214+
t.Parallel()
215+
216+
context := map[string]interface{}{
217+
"random_suffix": acctest.RandString(t, 10),
218+
}
219+
220+
acctest.VcrTest(t, resource.TestCase{
221+
PreCheck: func() { acctest.AccTestPreCheck(t) },
222+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
223+
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
224+
Steps: []resource.TestStep{
225+
{
226+
Config: testAccApphubApplication_applicationInvalidConfig1(context),
227+
ExpectError: regexp.MustCompile("Error validating location global with REGIONAL scope type"),
228+
},
229+
{
230+
Config: testAccApphubApplication_applicationInvalidConfig2(context),
231+
ExpectError: regexp.MustCompile("Error validating location us-east1 with GLOBAL scope type"),
232+
},
233+
},
234+
})
235+
}
236+
237+
func testAccApphubApplication_applicationInvalidConfig1(context map[string]interface{}) string {
238+
return acctest.Nprintf(`
239+
240+
resource "google_apphub_application" "invalid_example" {
241+
location = "global"
242+
application_id = "tf-test-invalid-example-application%{random_suffix}"
243+
scope {
244+
type = "REGIONAL"
245+
}
246+
}
247+
`, context)
248+
}
249+
250+
func testAccApphubApplication_applicationInvalidConfig2(context map[string]interface{}) string {
251+
return acctest.Nprintf(`
252+
253+
resource "google_apphub_application" "invalid_example" {
254+
location = "us-east1"
255+
application_id = "tf-test-invalid-example-application%{random_suffix}"
256+
scope {
257+
type = "GLOBAL"
258+
}
259+
}
260+
`, context)
261+
}

0 commit comments

Comments
 (0)