Skip to content

Commit b3decc3

Browse files
apichickBBBmau
authored andcommitted
Added google_apigee_app_group resource (GoogleCloudPlatform#12020)
1 parent d9ba0c7 commit b3decc3

6 files changed

+417
-0
lines changed

mmv1/products/apigee/AppGroup.yaml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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: "AppGroup"
16+
description: |
17+
An `AppGroup` in Apigee.
18+
references:
19+
guides:
20+
"Organizing client app ownership": "https://cloud.google.com/apigee/docs/api-platform/publish/organizing-client-app-ownership"
21+
api: "https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.appgroups"
22+
docs:
23+
base_url: "appgroups"
24+
self_link: "{{org_id}}/appgroups/{{name}}"
25+
create_url: "{{org_id}}/appgroups"
26+
import_format:
27+
- "{{org_id}}/appgroups/{{name}}"
28+
- "{{org_id}}/{{name}}"
29+
custom_code:
30+
custom_import: "templates/terraform/custom_import/apigee_app_group.go.tmpl"
31+
examples:
32+
- name: "apigee_app_group_basic"
33+
vars:
34+
app_group_name: "my-app-group"
35+
exclude_test: true
36+
- name: "apigee_app_group_basic_test"
37+
primary_resource_id: "apigee_app_group"
38+
test_env_vars:
39+
org_id: "ORG_ID"
40+
billing_account: "BILLING_ACCT"
41+
exclude_docs: true
42+
skip_vcr: true
43+
- name: "apigee_app_group_with_attributes"
44+
vars:
45+
app_group_name: "my-app-group"
46+
exclude_test: true
47+
- name: "apigee_app_group_with_attributes_test"
48+
primary_resource_id: "apigee_app_group"
49+
test_env_vars:
50+
org_id: "ORG_ID"
51+
billing_account: "BILLING_ACCT"
52+
exclude_docs: true
53+
skip_vcr: true
54+
parameters:
55+
- name: "orgId"
56+
type: String
57+
description: |
58+
The Apigee Organization associated with the Apigee app group,
59+
in the format `organizations/{{org_name}}`.
60+
url_param_only: true
61+
required: true
62+
immutable: true
63+
properties:
64+
- name: "appGroupId"
65+
type: String
66+
description: |
67+
Internal identifier that cannot be edited
68+
output: true
69+
- name: "name"
70+
type: String
71+
description: |
72+
Name of the AppGroup. Characters you can use in the name are restricted to: A-Z0-9._-$ %.
73+
required: true
74+
immutable: true
75+
- name: "channelUri"
76+
type: String
77+
description: |
78+
A reference to the associated storefront/marketplace.
79+
- name: "channelId"
80+
type: String
81+
description: |
82+
Channel identifier identifies the owner maintaing this grouping.
83+
- name: "displayName"
84+
type: String
85+
description: |
86+
App group name displayed in the UI
87+
- name: "organization"
88+
type: String
89+
description: |
90+
App group name displayed in the UI
91+
output: true
92+
- name: "status"
93+
type: Enum
94+
description: |
95+
Valid values are active or inactive. Note that the status of the AppGroup should be updated via UpdateAppGroupRequest by setting the action as active or inactive.
96+
enum_values:
97+
- active
98+
- inactive
99+
- name: "attributes"
100+
type: Array
101+
description: |
102+
A list of attributes
103+
item_type:
104+
type: NestedObject
105+
properties:
106+
- name: "name"
107+
type: String
108+
description: |
109+
Key of the attribute
110+
- name: "value"
111+
type: String
112+
description: |
113+
Value of the attribute
114+
- name: "createdAt"
115+
type: String
116+
description: |
117+
Created time as milliseconds since epoch.
118+
output: true
119+
- name: "lastModifiedAt"
120+
type: String
121+
description: |
122+
Modified time as milliseconds since epoch.
123+
output: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
config := meta.(*transport_tpg.Config)
2+
3+
// current import_formats cannot import fields with forward slashes in their value
4+
if err := tpgresource.ParseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
5+
return nil, err
6+
}
7+
8+
nameParts := strings.Split(d.Get("name").(string), "/")
9+
if len(nameParts) == 4 {
10+
// `organizations/{{"{{"}}org_name{{"}}"}}/appgroups/{{"{{"}}name{{"}}"}}`
11+
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
12+
if err := d.Set("org_id", orgId); err != nil {
13+
return nil, fmt.Errorf("Error setting org_id: %s", err)
14+
}
15+
if err := d.Set("name", nameParts[3]); err != nil {
16+
return nil, fmt.Errorf("Error setting name: %s", err)
17+
}
18+
} else if len(nameParts) == 3 {
19+
// `organizations/{{"{{"}}org_name{{"}}"}}/{{"{{"}}name{{"}}"}}`
20+
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
21+
if err := d.Set("org_id", orgId); err != nil {
22+
return nil, fmt.Errorf("Error setting org_id: %s", err)
23+
}
24+
if err := d.Set("name", nameParts[2]); err != nil {
25+
return nil, fmt.Errorf("Error setting name: %s", err)
26+
}
27+
} else {
28+
return nil, fmt.Errorf(
29+
"Saw %s when the name is expected to have shape %s or %s",
30+
d.Get("name"),
31+
"organizations/{{"{{"}}org_name{{"}}"}}/appgroups/{{"{{"}}name{{"}}"}}",
32+
"organizations/{{"{{"}}org_name{{"}}"}}/{{"{{"}}name{{"}}"}}")
33+
}
34+
35+
// Replace import id for the resource id
36+
id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}org_id{{"}}"}}/appgroups/{{"{{"}}name{{"}}"}}")
37+
if err != nil {
38+
return nil, fmt.Errorf("Error constructing id: %s", err)
39+
}
40+
d.SetId(id)
41+
42+
return []*schema.ResourceData{d}, nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
data "google_client_config" "current" {}
2+
3+
resource "google_compute_network" "apigee_network" {
4+
name = "apigee-network"
5+
}
6+
7+
resource "google_compute_global_address" "apigee_range" {
8+
name = "apigee-range"
9+
purpose = "VPC_PEERING"
10+
address_type = "INTERNAL"
11+
prefix_length = 16
12+
network = google_compute_network.apigee_network.id
13+
}
14+
15+
resource "google_service_networking_connection" "apigee_vpc_connection" {
16+
network = google_compute_network.apigee_network.id
17+
service = "servicenetworking.googleapis.com"
18+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
19+
}
20+
21+
resource "google_apigee_organization" "apigee_org" {
22+
analytics_region = "us-central1"
23+
project_id = data.google_client_config.current.project
24+
authorized_network = google_compute_network.apigee_network.id
25+
depends_on = [google_service_networking_connection.apigee_vpc_connection]
26+
}
27+
28+
resource "google_apigee_instance" "apigee_instance" {
29+
name = "instance"
30+
location = "us-central1"
31+
org_id = google_apigee_organization.apigee_org.id
32+
peering_cidr_range = "SLASH_22"
33+
}
34+
35+
resource "google_apigee_app_group" "apigee_app_group" {
36+
name = "{{index $.Vars "app_group_name"}}"
37+
display_name = "Test app group"
38+
channel_id = "storefront"
39+
channel_uri = "https://my-dev-portal.org/groups/my-group"
40+
status = "active"
41+
org_id = google_apigee_organization.apigee_org.id
42+
depends_on = [
43+
google_apigee_instance.apigee_instance
44+
]
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
resource "google_project" "project" {
2+
project_id = "tf-test%{random_suffix}"
3+
name = "tf-test%{random_suffix}"
4+
org_id = "{{index $.TestEnvVars "org_id"}}"
5+
billing_account = "{{index $.TestEnvVars "billing_account"}}"
6+
deletion_policy = "DELETE"
7+
}
8+
9+
resource "google_project_service" "apigee" {
10+
project = google_project.project.project_id
11+
service = "apigee.googleapis.com"
12+
}
13+
14+
resource "google_project_service" "compute" {
15+
project = google_project.project.project_id
16+
service = "compute.googleapis.com"
17+
}
18+
19+
resource "google_project_service" "servicenetworking" {
20+
project = google_project.project.project_id
21+
service = "servicenetworking.googleapis.com"
22+
}
23+
24+
resource "google_compute_network" "apigee_network" {
25+
name = "apigee-network"
26+
project = google_project.project.project_id
27+
depends_on = [google_project_service.compute]
28+
}
29+
30+
resource "google_compute_global_address" "apigee_range" {
31+
name = "apigee-range"
32+
purpose = "VPC_PEERING"
33+
address_type = "INTERNAL"
34+
prefix_length = 16
35+
network = google_compute_network.apigee_network.id
36+
project = google_project.project.project_id
37+
}
38+
39+
resource "google_service_networking_connection" "apigee_vpc_connection" {
40+
network = google_compute_network.apigee_network.id
41+
service = "servicenetworking.googleapis.com"
42+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
43+
depends_on = [google_project_service.servicenetworking]
44+
}
45+
46+
resource "google_apigee_organization" "apigee_org" {
47+
analytics_region = "us-central1"
48+
project_id = google_project.project.project_id
49+
authorized_network = google_compute_network.apigee_network.id
50+
depends_on = [
51+
google_service_networking_connection.apigee_vpc_connection,
52+
google_project_service.apigee,
53+
]
54+
}
55+
56+
resource "google_apigee_instance" "apigee_instance" {
57+
name = "tf-test%{random_suffix}"
58+
location = "us-central1"
59+
org_id = google_apigee_organization.apigee_org.id
60+
peering_cidr_range = "SLASH_22"
61+
}
62+
63+
resource "google_apigee_app_group" "{{$.PrimaryResourceId}}" {
64+
name = "tf-test%{random_suffix}"
65+
display_name = "Test app group"
66+
channel_id = "storefront"
67+
channel_uri = "https://my-dev-portal.org/groups/my-group"
68+
status = "active"
69+
org_id = google_apigee_organization.apigee_org.id
70+
depends_on = [
71+
google_apigee_instance.apigee_instance
72+
]
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
data "google_client_config" "current" {}
2+
3+
resource "google_compute_network" "apigee_network" {
4+
name = "apigee-network"
5+
}
6+
7+
resource "google_compute_global_address" "apigee_range" {
8+
name = "apigee-range"
9+
purpose = "VPC_PEERING"
10+
address_type = "INTERNAL"
11+
prefix_length = 16
12+
network = google_compute_network.apigee_network.id
13+
}
14+
15+
resource "google_service_networking_connection" "apigee_vpc_connection" {
16+
network = google_compute_network.apigee_network.id
17+
service = "servicenetworking.googleapis.com"
18+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
19+
}
20+
21+
resource "google_apigee_organization" "apigee_org" {
22+
analytics_region = "us-central1"
23+
project_id = data.google_client_config.current.project
24+
authorized_network = google_compute_network.apigee_network.id
25+
depends_on = [google_service_networking_connection.apigee_vpc_connection]
26+
}
27+
28+
resource "google_apigee_instance" "apigee_instance" {
29+
name = "instance"
30+
location = "us-central1"
31+
org_id = google_apigee_organization.apigee_org.id
32+
peering_cidr_range = "SLASH_22"
33+
}
34+
35+
resource "google_apigee_app_group" "apigee_app_group" {
36+
name = "{{index $.Vars "app_group_name"}}"
37+
display_name = "Test app group"
38+
channel_id = "storefront"
39+
channel_uri = "https://my-dev-portal.org/groups/my-group"
40+
status = "active"
41+
org_id = google_apigee_organization.apigee_org.id
42+
attributes {
43+
name = "business_unit"
44+
value = "HR"
45+
}
46+
attributes {
47+
name = "department"
48+
value = "payroll"
49+
}
50+
depends_on = [
51+
google_apigee_instance.apigee_instance
52+
]
53+
}

0 commit comments

Comments
 (0)