Skip to content

Commit ff7f731

Browse files
authored
Add Security Gateway Application resource (GoogleCloudPlatform#12837)
1 parent 67558a9 commit ff7f731

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed
+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: Application
16+
description: Specifies application endpoint(s) to protect behind a Security Gateway.
17+
base_url: projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications
18+
update_mask: true
19+
self_link: projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications/{{application_id}}
20+
create_url: projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications?applicationId={{application_id}}
21+
update_verb: PATCH
22+
id_format: projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications/{{application_id}}
23+
import_format:
24+
- projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications/{{application_id}}
25+
iam_policy:
26+
method_name_separator: ':'
27+
iam_conditions_request_type: 'QUERY_PARAM_NESTED'
28+
allowed_iam_role: 'roles/beyondcorp.securityGatewayUser'
29+
parent_resource_attribute: 'application_id'
30+
import_format:
31+
- 'projects/{{project}}/locations/global/securityGateways/{{security_gateways_id}}/applications/{{application_id}}'
32+
- '{{application_id}}'
33+
examples:
34+
- name: beyondcorp_security_gateway_application_basic
35+
primary_resource_id: example
36+
primary_resource_name: 'fmt.Sprintf("default%s", context["random_suffix"]), fmt.Sprintf("google%s", context["random_suffix"])'
37+
vars:
38+
security_gateway_name: default
39+
application_name: google
40+
autogen_async: true
41+
async:
42+
operation:
43+
timeouts:
44+
insert_minutes: 20
45+
update_minutes: 20
46+
delete_minutes: 20
47+
base_url: '{{op_id}}'
48+
actions:
49+
- create
50+
- delete
51+
- update
52+
type: OpAsync
53+
result:
54+
resource_inside_response: true
55+
error: {}
56+
include_project: false
57+
autogen_status: QXBwbGljYXRpb24=
58+
parameters:
59+
- name: securityGatewaysId
60+
type: String
61+
description: Part of `parent`. See documentation of `projectsId`.
62+
immutable: true
63+
url_param_only: true
64+
required: true
65+
- name: applicationId
66+
type: String
67+
description: |-
68+
Optional. User-settable Application resource ID.
69+
* Must start with a letter.
70+
* Must contain between 4-63 characters from `/a-z-/`.
71+
* Must end with a number or letter.
72+
immutable: true
73+
url_param_only: true
74+
required: true
75+
properties:
76+
- name: createTime
77+
type: String
78+
description: Output only. Timestamp when the resource was created.
79+
output: true
80+
- name: displayName
81+
type: String
82+
description: |-
83+
Optional. An arbitrary user-provided name for the Application resource.
84+
Cannot exceed 64 characters.
85+
- name: endpointMatchers
86+
type: Array
87+
description: |-
88+
Required. Endpoint matchers associated with an application.
89+
A combination of hostname and ports as endpoint matcher is used to match
90+
the application.
91+
Match conditions for OR logic.
92+
An array of match conditions to allow for multiple matching criteria.
93+
The rule is considered a match if one the conditions are met.
94+
The conditions can be one of the following combination
95+
(Hostname), (Hostname & Ports)
96+
97+
EXAMPLES:
98+
Hostname - ("*.abc.com"), ("xyz.abc.com")
99+
Hostname and Ports - ("abc.com" and "22"), ("abc.com" and "22,33") etc
100+
required: true
101+
item_type:
102+
type: NestedObject
103+
properties:
104+
- name: hostname
105+
type: String
106+
description: Required. Hostname of the application.
107+
required: true
108+
- name: ports
109+
type: Array
110+
description: Optional. Ports of the application.
111+
item_type:
112+
type: Integer
113+
- name: name
114+
type: String
115+
description: Identifier. Name of the resource.
116+
output: true
117+
- name: updateTime
118+
type: String
119+
description: Output only. Timestamp when the resource was last modified.
120+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "google_beyondcorp_security_gateway" "default" {
2+
security_gateway_id = "{{index $.Vars "security_gateway_name"}}"
3+
display_name = "My Security Gateway resource"
4+
hubs { region = "us-central1" }
5+
}
6+
7+
resource "google_beyondcorp_application" "{{$.PrimaryResourceId}}" {
8+
security_gateways_id = google_beyondcorp_security_gateway.default.security_gateway_id
9+
application_id = "{{index $.Vars "application_name"}}"
10+
endpoint_matchers {
11+
hostname = "google.com"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package beyondcorp_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
8+
9+
"github.com/hashicorp/terraform-provider-google/google/acctest"
10+
)
11+
12+
func TestAccBeyondcorpApplication_beyondcorpSecurityGatewayApplicationBasicExample_update(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"random_suffix": acctest.RandString(t, 10),
17+
}
18+
19+
acctest.VcrTest(t, resource.TestCase{
20+
PreCheck: func() { acctest.AccTestPreCheck(t) },
21+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
22+
Steps: []resource.TestStep{
23+
{
24+
Config: testAccBeyondcorpApplication_beyondcorpSecurityGatewayApplicationBasicExample_basic(context),
25+
},
26+
{
27+
ResourceName: "google_beyondcorp_application.example",
28+
ImportState: true,
29+
ImportStateVerify: true,
30+
ImportStateVerifyIgnore: []string{"application_id", "security_gateways_id"},
31+
},
32+
{
33+
Config: testAccBeyondcorpApplication_beyondcorpSecurityGatewayApplicationBasicExample_update(context),
34+
ConfigPlanChecks: resource.ConfigPlanChecks{
35+
PreApply: []plancheck.PlanCheck{
36+
plancheck.ExpectResourceAction("google_beyondcorp_application.example", plancheck.ResourceActionUpdate),
37+
},
38+
},
39+
},
40+
{
41+
ResourceName: "google_beyondcorp_application.example",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
ImportStateVerifyIgnore: []string{"application_id", "security_gateways_id"},
45+
},
46+
},
47+
})
48+
}
49+
50+
func testAccBeyondcorpApplication_beyondcorpSecurityGatewayApplicationBasicExample_basic(context map[string]interface{}) string {
51+
return acctest.Nprintf(`
52+
resource "google_beyondcorp_security_gateway" "default" {
53+
security_gateway_id = "default%{random_suffix}"
54+
display_name = "My Security Gateway resource"
55+
hubs { region = "us-central1" }
56+
}
57+
58+
resource "google_beyondcorp_application" "example" {
59+
security_gateways_id = google_beyondcorp_security_gateway.default.security_gateway_id
60+
application_id = "google%{random_suffix}"
61+
endpoint_matchers {
62+
hostname = "google.com"
63+
}
64+
}
65+
`, context)
66+
}
67+
68+
func testAccBeyondcorpApplication_beyondcorpSecurityGatewayApplicationBasicExample_update(context map[string]interface{}) string {
69+
return acctest.Nprintf(`
70+
resource "google_beyondcorp_security_gateway" "default" {
71+
security_gateway_id = "default%{random_suffix}"
72+
display_name = "My Security Gateway resource"
73+
hubs { region = "us-central1" }
74+
}
75+
76+
resource "google_beyondcorp_application" "example" {
77+
security_gateways_id = google_beyondcorp_security_gateway.default.security_gateway_id
78+
display_name = "Updated Name"
79+
application_id = "google%{random_suffix}"
80+
endpoint_matchers {
81+
hostname = "google.com"
82+
}
83+
}
84+
`, context)
85+
}

0 commit comments

Comments
 (0)