Skip to content

Commit 79b564b

Browse files
Add support for global application in Apphub (#12017) (#8504)
[upstream:17c4060613d42178fcb9de8e9f3a578d3b243c2a] Signed-off-by: Modular Magician <[email protected]>
1 parent e2d8b84 commit 79b564b

File tree

5 files changed

+150
-16
lines changed

5 files changed

+150
-16
lines changed

.changelog/12017.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
apphub: added `GLOBAL` enum value to `scope.type` field in `google_apphub_application` resource
3+
```

google-beta/services/apphub/resource_apphub_application.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package apphub
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"log"
2324
"net/http"
@@ -33,6 +34,24 @@ import (
3334
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
3435
)
3536

37+
func apphubApplicationCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
38+
if diff.HasChange("location") || diff.HasChange("scope.0.type") {
39+
location := diff.Get("location")
40+
scope_type := diff.Get("scope.0.type")
41+
42+
if scope_type == "GLOBAL" {
43+
if location != "global" {
44+
return fmt.Errorf("Error validating location %s with %s scope type", location, scope_type)
45+
}
46+
} else {
47+
if location == "global" {
48+
return fmt.Errorf("Error validating location %s with %s scope type", location, scope_type)
49+
}
50+
}
51+
}
52+
return nil
53+
}
54+
3655
func ResourceApphubApplication() *schema.Resource {
3756
return &schema.Resource{
3857
Create: resourceApphubApplicationCreate,
@@ -51,6 +70,7 @@ func ResourceApphubApplication() *schema.Resource {
5170
},
5271

5372
CustomizeDiff: customdiff.All(
73+
apphubApplicationCustomizeDiff,
5474
tpgresource.DefaultProviderProject,
5575
),
5676

@@ -77,10 +97,11 @@ func ResourceApphubApplication() *schema.Resource {
7797
"type": {
7898
Type: schema.TypeString,
7999
Required: true,
80-
ValidateFunc: verify.ValidateEnum([]string{"REGIONAL"}),
100+
ValidateFunc: verify.ValidateEnum([]string{"REGIONAL", "GLOBAL"}),
81101
Description: `Required. Scope Type.
82102
Possible values:
83-
REGIONAL Possible values: ["REGIONAL"]`,
103+
REGIONAL
104+
GLOBAL Possible values: ["REGIONAL", "GLOBAL"]`,
84105
},
85106
},
86107
},

google-beta/services/apphub/resource_apphub_application_generated_test.go

+49-8
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ import (
3030
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
3131
)
3232

33-
func TestAccApphubApplication_applicationBasicExample(t *testing.T) {
33+
func TestAccApphubApplication_apphubApplicationBasicExample(t *testing.T) {
3434
t.Parallel()
3535

3636
context := map[string]interface{}{
37+
"location": "us-east1",
38+
"scope_type": "REGIONAL",
3739
"random_suffix": acctest.RandString(t, 10),
3840
}
3941

@@ -43,7 +45,7 @@ func TestAccApphubApplication_applicationBasicExample(t *testing.T) {
4345
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
4446
Steps: []resource.TestStep{
4547
{
46-
Config: testAccApphubApplication_applicationBasicExample(context),
48+
Config: testAccApphubApplication_apphubApplicationBasicExample(context),
4749
},
4850
{
4951
ResourceName: "google_apphub_application.example",
@@ -55,19 +57,58 @@ func TestAccApphubApplication_applicationBasicExample(t *testing.T) {
5557
})
5658
}
5759

58-
func testAccApphubApplication_applicationBasicExample(context map[string]interface{}) string {
60+
func testAccApphubApplication_apphubApplicationBasicExample(context map[string]interface{}) string {
5961
return acctest.Nprintf(`
6062
resource "google_apphub_application" "example" {
61-
location = "us-east1"
63+
location = "%{location}"
6264
application_id = "tf-test-example-application%{random_suffix}"
6365
scope {
64-
type = "REGIONAL"
66+
type = "%{scope_type}"
67+
}
68+
}
69+
`, context)
70+
}
71+
72+
func TestAccApphubApplication_apphubApplicationGlobalBasicExample(t *testing.T) {
73+
t.Parallel()
74+
75+
context := map[string]interface{}{
76+
"location": "global",
77+
"scope_type": "GLOBAL",
78+
"random_suffix": acctest.RandString(t, 10),
79+
}
80+
81+
acctest.VcrTest(t, resource.TestCase{
82+
PreCheck: func() { acctest.AccTestPreCheck(t) },
83+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
84+
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
85+
Steps: []resource.TestStep{
86+
{
87+
Config: testAccApphubApplication_apphubApplicationGlobalBasicExample(context),
88+
},
89+
{
90+
ResourceName: "google_apphub_application.example",
91+
ImportState: true,
92+
ImportStateVerify: true,
93+
ImportStateVerifyIgnore: []string{"application_id", "location"},
94+
},
95+
},
96+
})
97+
}
98+
99+
func testAccApphubApplication_apphubApplicationGlobalBasicExample(context map[string]interface{}) string {
100+
return acctest.Nprintf(`
101+
resource "google_apphub_application" "example" {
102+
location = "%{location}"
103+
application_id = "tf-test-example-application%{random_suffix}"
104+
scope {
105+
type = "%{scope_type}"
65106
}
66107
}
67108
`, context)
68109
}
69110

70-
func TestAccApphubApplication_applicationFullExample(t *testing.T) {
111+
func TestAccApphubApplication_apphubApplicationFullExample(t *testing.T) {
71112
t.Parallel()
72113

73114
context := map[string]interface{}{
@@ -80,7 +121,7 @@ func TestAccApphubApplication_applicationFullExample(t *testing.T) {
80121
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
81122
Steps: []resource.TestStep{
82123
{
83-
Config: testAccApphubApplication_applicationFullExample(context),
124+
Config: testAccApphubApplication_apphubApplicationFullExample(context),
84125
},
85126
{
86127
ResourceName: "google_apphub_application.example2",
@@ -92,7 +133,7 @@ func TestAccApphubApplication_applicationFullExample(t *testing.T) {
92133
})
93134
}
94135

95-
func testAccApphubApplication_applicationFullExample(context map[string]interface{}) string {
136+
func testAccApphubApplication_apphubApplicationFullExample(context map[string]interface{}) string {
96137
return acctest.Nprintf(`
97138
resource "google_apphub_application" "example2" {
98139
location = "us-east1"

google-beta/services/apphub/resource_apphub_application_test.go

+52-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package apphub_test
44

55
import (
6+
"regexp"
67
"testing"
78

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

website/docs/r/apphub_application.html.markdown

+23-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ Application is a functional grouping of Services and Workloads that helps achiev
2424

2525

2626
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
27-
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=application_basic&open_in_editor=main.tf" target="_blank">
27+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=apphub_application_basic&open_in_editor=main.tf" target="_blank">
2828
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
2929
</a>
3030
</div>
31-
## Example Usage - Application Basic
31+
## Example Usage - Apphub Application Basic
3232

3333

3434
```hcl
@@ -41,11 +41,28 @@ resource "google_apphub_application" "example" {
4141
}
4242
```
4343
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
44-
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=application_full&open_in_editor=main.tf" target="_blank">
44+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=apphub_application_global_basic&open_in_editor=main.tf" target="_blank">
4545
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
4646
</a>
4747
</div>
48-
## Example Usage - Application Full
48+
## Example Usage - Apphub Application Global Basic
49+
50+
51+
```hcl
52+
resource "google_apphub_application" "example" {
53+
location = "global"
54+
application_id = "example-application"
55+
scope {
56+
type = "GLOBAL"
57+
}
58+
}
59+
```
60+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
61+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=apphub_application_full&open_in_editor=main.tf" target="_blank">
62+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
63+
</a>
64+
</div>
65+
## Example Usage - Apphub Application Full
4966

5067

5168
```hcl
@@ -106,7 +123,8 @@ The following arguments are supported:
106123
Required. Scope Type.
107124
Possible values:
108125
REGIONAL
109-
Possible values are: `REGIONAL`.
126+
GLOBAL
127+
Possible values are: `REGIONAL`, `GLOBAL`.
110128

111129
- - -
112130

0 commit comments

Comments
 (0)