Skip to content

Commit 06dd635

Browse files
sauragrawalDawid212
authored andcommitted
Adding Apigee Dns Zone resource support (GoogleCloudPlatform#13060)
1 parent f26a254 commit 06dd635

File tree

4 files changed

+271
-0
lines changed

4 files changed

+271
-0
lines changed

mmv1/products/apigee/DnsZone.yaml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright 2025 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: 'DnsZone'
16+
description: |
17+
Apigee Dns Zone.
18+
references:
19+
guides:
20+
'Creating a DnsZone': 'https://cloud.google.com/apigee/docs/api-platform/get-started/create-dns'
21+
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.dnsZones/create'
22+
docs:
23+
base_url: 'dnsZones'
24+
self_link: '{{org_id}}/dnsZones/{{dns_zone_id}}'
25+
create_url: '{{org_id}}/dnsZones?dnsZoneId={{dns_zone_id}}'
26+
delete_url: '{{org_id}}/dnsZones/{{dns_zone_id}}'
27+
immutable: true
28+
import_format:
29+
- '{{org_id}}/dnsZones/{{dns_zone_id}}'
30+
- '{{org_id}}/{{dns_zone_id}}'
31+
timeouts:
32+
insert_minutes: 30
33+
update_minutes: 20
34+
delete_minutes: 30
35+
autogen_async: true
36+
async:
37+
actions: ['create', 'delete', 'update']
38+
type: 'OpAsync'
39+
operation:
40+
base_url: '{{op_id}}'
41+
result:
42+
resource_inside_response: true
43+
custom_code:
44+
custom_import: 'templates/terraform/custom_import/apigee_dns_zone.go.tmpl'
45+
examples:
46+
- name: 'apigee_dns_zone_basic'
47+
exclude_test: true
48+
- name: 'apigee_dns_zone_basic_test'
49+
primary_resource_id: 'apigee_dns_zone'
50+
min_version: 'beta'
51+
test_env_vars:
52+
org_id: 'ORG_ID'
53+
billing_account: 'BILLING_ACCT'
54+
exclude_docs: true
55+
skip_vcr: true
56+
external_providers: ["time"]
57+
exclude_sweeper: true
58+
parameters:
59+
- name: 'orgId'
60+
type: String
61+
description: |
62+
The Apigee Organization associated with the Apigee instance,
63+
in the format `organizations/{{org_name}}`.
64+
url_param_only: true
65+
required: true
66+
immutable: true
67+
- name: 'dnsZoneId'
68+
type: String
69+
description: |
70+
ID of the dns zone.
71+
url_param_only: true
72+
required: true
73+
immutable: true
74+
properties:
75+
- name: 'name'
76+
type: String
77+
description: |
78+
Name of the Dns Zone in the following format:
79+
organizations/{organization}/dnsZones/{dnsZone}.
80+
output: true
81+
- name: 'domain'
82+
type: String
83+
description: |
84+
Doamin for the zone.
85+
required: true
86+
- name: 'description'
87+
type: String
88+
description: |
89+
Description for the zone.
90+
required: true
91+
- name: 'peeringConfig'
92+
type: NestedObject
93+
description: |
94+
Peering zone config
95+
required: true
96+
properties:
97+
- name: 'targetProjectId'
98+
type: String
99+
description: |
100+
The ID of the project that contains the producer VPC network.
101+
required: true
102+
- name: 'targetNetworkId'
103+
type: String
104+
description: |
105+
The name of the producer VPC network.
106+
required: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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{{"}}"}}/dnsZone/{{"{{"}}dns_zone_id{{"}}"}}`
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("dns_zone_id", nameParts[3]); err != nil {
16+
return nil, fmt.Errorf("Error setting dns_zone_id: %s", err)
17+
}
18+
} else {
19+
return nil, fmt.Errorf(
20+
"Saw %s when the name is expected to have shape %s",
21+
d.Get("name"),
22+
"organizations/{{"{{"}}org_name{{"}}"}}/dnsZone/{{"{{"}}name{{"}}"}}")
23+
}
24+
25+
// Replace import id for the resource id
26+
id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}name{{"}}"}}")
27+
if err != nil {
28+
return nil, fmt.Errorf("Error constructing id: %s", err)
29+
}
30+
d.SetId(id)
31+
32+
return []*schema.ResourceData{d}, nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
data "google_client_config" "current" {}
2+
3+
resource "google_compute_network" "apigee_network" {
4+
name = "apigee-network"
5+
}
6+
7+
resource "google_apigee_organization" "org" {
8+
description = "Terraform-provisioned basic Apigee Org without VPC Peering."
9+
analytics_region = "us-central1"
10+
project_id = data.google_client_config.current.project
11+
disable_vpc_peering = true
12+
}
13+
14+
resource "google_apigee_dns_zone" "apigee_dns_zone" {
15+
org_id = google_apigee_organization.apigee_org.id
16+
dns_zone_id = "test1"
17+
domain = "foo.com"
18+
description = "test"
19+
peering_config {
20+
target_project_id = data.google_client_config.current.project
21+
target_network_id = google_compute_network.apigee_network.id
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
resource "google_project" "project" {
2+
provider = google-beta
3+
4+
project_id = "tf-test%{random_suffix}"
5+
name = "tf-test%{random_suffix}"
6+
org_id = "{{index $.TestEnvVars "org_id"}}"
7+
billing_account = "{{index $.TestEnvVars "billing_account"}}"
8+
deletion_policy = "DELETE"
9+
}
10+
11+
resource "time_sleep" "wait_120_seconds" {
12+
create_duration = "120s"
13+
depends_on = [google_project.project]
14+
}
15+
16+
resource "google_project_service" "apigee" {
17+
provider = google-beta
18+
19+
project = google_project.project.project_id
20+
service = "apigee.googleapis.com"
21+
}
22+
23+
resource "google_project_service" "compute" {
24+
provider = google-beta
25+
26+
project = google_project.project.project_id
27+
service = "compute.googleapis.com"
28+
depends_on = [
29+
google_project_service.container,
30+
time_sleep.wait_120_seconds,
31+
]
32+
}
33+
34+
resource "google_project_service" "container" {
35+
provider = google-beta
36+
37+
project = google_project.project.project_id
38+
service = "compute.googleapis.com"
39+
}
40+
41+
resource "google_project_service" "dns" {
42+
provider = google-beta
43+
44+
project = google_project.project.project_id
45+
service = "dns.googleapis.com"
46+
}
47+
48+
resource "google_compute_network" "apigee_network" {
49+
provider = google-beta
50+
51+
name = "apigee-network"
52+
project = google_project.project.project_id
53+
depends_on = [google_project_service.compute]
54+
}
55+
56+
resource "google_project_service_identity" "apigee_sa" {
57+
provider = google-beta
58+
59+
project = google_project.project.project_id
60+
service = google_project_service.apigee.service
61+
depends_on = [google_project_service.apigee]
62+
}
63+
64+
resource "time_sleep" "wait_60_seconds" {
65+
create_duration = "60s"
66+
depends_on = [google_project_service_identity.apigee_sa]
67+
}
68+
69+
resource "google_project_iam_member" "project" {
70+
provider = google-beta
71+
72+
project = google_project.project.project_id
73+
role = "roles/dns.peer"
74+
member = google_project_service_identity.apigee_sa.member
75+
depends_on = [
76+
google_project_service_identity.apigee_sa,
77+
time_sleep.wait_60_seconds,
78+
]
79+
}
80+
81+
resource "google_apigee_organization" "apigee_org" {
82+
provider = google-beta
83+
84+
analytics_region = "us-central1"
85+
project_id = google_project.project.project_id
86+
disable_vpc_peering = true
87+
depends_on = [
88+
google_project_service.compute,
89+
google_project_service.container,
90+
google_project_service.dns,
91+
google_project_service.apigee,
92+
google_project_iam_member.project,
93+
]
94+
}
95+
96+
resource "google_apigee_dns_zone" "{{$.PrimaryResourceId}}" {
97+
provider = google-beta
98+
99+
dns_zone_id = "tf-test%{random_suffix}"
100+
org_id = google_apigee_organization.apigee_org.id
101+
domain = "foo.com"
102+
description = "test"
103+
peering_config {
104+
target_project_id = google_project.project.project_id
105+
target_network_id = "apigee-network"
106+
}
107+
depends_on = [
108+
google_apigee_organization.apigee_org
109+
]
110+
}

0 commit comments

Comments
 (0)