Skip to content

Commit 7c0970f

Browse files
Add "consumerAcceptList" and "serviceAttachment" to ApigeeInstance. (#5862) (#4260)
* Add support IAM policy for the Environment of Apigee X * Add support IAM policy for the Environment of Apigee X * Add support IAM policy for the Environment of Apigee X * Add support IAM policy for the Environment of Apigee X * Revert all changes to test files. * Revert all changes to test files. * Revert all changes to test files. * Add primary_resource_name to fix tests. * Update iam_attributes.tf.erb to honor skip_test. * Don't reject skip_tests when example is nil. * Update mmv1/products/apigee/api.yaml Co-authored-by: Stephen Lewis (Burrows) <[email protected]> * Fix primary_resource_name for apigee organization name. * Add "consumerAcceptList" and "serviceAttachment" to ApigeeInstance. * Fix new test * Add tests Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 12f973d commit 7c0970f

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed

.changelog/5862.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
Add "consumerAcceptList" and "serviceAttachment" to ApigeeInstance.
3+
```

google-beta/resource_apigee_instance.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ func resourceApigeeInstance() *schema.Resource {
5959
Description: `The Apigee Organization associated with the Apigee instance,
6060
in the format 'organizations/{{org_name}}'.`,
6161
},
62+
"consumer_accept_list": {
63+
Type: schema.TypeList,
64+
Computed: true,
65+
Optional: true,
66+
ForceNew: true,
67+
Description: `Optional. Customer accept list represents the list of projects (id/number) on customer
68+
side that can privately connect to the service attachment. It is an optional field
69+
which the customers can provide during the instance creation. By default, the customer
70+
project associated with the Apigee organization will be included to the list.`,
71+
Elem: &schema.Schema{
72+
Type: schema.TypeString,
73+
},
74+
},
6275
"description": {
6376
Type: schema.TypeString,
6477
Optional: true,
@@ -108,6 +121,13 @@ see [CidrRange](https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/
108121
Computed: true,
109122
Description: `Output only. Port number of the exposed Apigee endpoint.`,
110123
},
124+
"service_attachment": {
125+
Type: schema.TypeString,
126+
Computed: true,
127+
Description: `Output only. Resource name of the service attachment created for the instance in
128+
the format: projects/*/regions/*/serviceAttachments/* Apigee customers can privately
129+
forward traffic to this service attachment using the PSC endpoints.`,
130+
},
111131
},
112132
UseJSONNumber: true,
113133
}
@@ -163,6 +183,12 @@ func resourceApigeeInstanceCreate(d *schema.ResourceData, meta interface{}) erro
163183
} else if v, ok := d.GetOkExists("disk_encryption_key_name"); !isEmptyValue(reflect.ValueOf(diskEncryptionKeyNameProp)) && (ok || !reflect.DeepEqual(v, diskEncryptionKeyNameProp)) {
164184
obj["diskEncryptionKeyName"] = diskEncryptionKeyNameProp
165185
}
186+
consumerAcceptListProp, err := expandApigeeInstanceConsumerAcceptList(d.Get("consumer_accept_list"), d, config)
187+
if err != nil {
188+
return err
189+
} else if v, ok := d.GetOkExists("consumer_accept_list"); !isEmptyValue(reflect.ValueOf(consumerAcceptListProp)) && (ok || !reflect.DeepEqual(v, consumerAcceptListProp)) {
190+
obj["consumerAcceptList"] = consumerAcceptListProp
191+
}
166192

167193
lockName, err := replaceVars(d, config, "{{org_id}}/apigeeInstances")
168194
if err != nil {
@@ -272,6 +298,12 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error
272298
if err := d.Set("port", flattenApigeeInstancePort(res["port"], d, config)); err != nil {
273299
return fmt.Errorf("Error reading Instance: %s", err)
274300
}
301+
if err := d.Set("consumer_accept_list", flattenApigeeInstanceConsumerAcceptList(res["consumerAcceptList"], d, config)); err != nil {
302+
return fmt.Errorf("Error reading Instance: %s", err)
303+
}
304+
if err := d.Set("service_attachment", flattenApigeeInstanceServiceAttachment(res["serviceAttachment"], d, config)); err != nil {
305+
return fmt.Errorf("Error reading Instance: %s", err)
306+
}
275307

276308
return nil
277309
}
@@ -399,6 +431,14 @@ func flattenApigeeInstancePort(v interface{}, d *schema.ResourceData, config *Co
399431
return v
400432
}
401433

434+
func flattenApigeeInstanceConsumerAcceptList(v interface{}, d *schema.ResourceData, config *Config) interface{} {
435+
return v
436+
}
437+
438+
func flattenApigeeInstanceServiceAttachment(v interface{}, d *schema.ResourceData, config *Config) interface{} {
439+
return v
440+
}
441+
402442
func expandApigeeInstanceName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
403443
return v, nil
404444
}
@@ -426,3 +466,7 @@ func expandApigeeInstanceDisplayName(v interface{}, d TerraformResourceData, con
426466
func expandApigeeInstanceDiskEncryptionKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
427467
return v, nil
428468
}
469+
470+
func expandApigeeInstanceConsumerAcceptList(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
471+
return v, nil
472+
}

google-beta/resource_apigee_instance_generated_test.go

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,199 @@ resource "google_apigee_instance" "apigee_instance" {
459459
`, context)
460460
}
461461

462+
func TestAccApigeeInstance_apigeeInstanceServiceAttachmentBasicTestExample(t *testing.T) {
463+
skipIfVcr(t)
464+
t.Parallel()
465+
466+
context := map[string]interface{}{
467+
"org_id": getTestOrgFromEnv(t),
468+
"billing_account": getTestBillingAccountFromEnv(t),
469+
"random_suffix": randString(t, 10),
470+
}
471+
472+
vcrTest(t, resource.TestCase{
473+
PreCheck: func() { testAccPreCheck(t) },
474+
Providers: testAccProviders,
475+
CheckDestroy: testAccCheckApigeeInstanceDestroyProducer(t),
476+
Steps: []resource.TestStep{
477+
{
478+
Config: testAccApigeeInstance_apigeeInstanceServiceAttachmentBasicTestExample(context),
479+
},
480+
{
481+
ResourceName: "google_apigee_instance.apigee_instance",
482+
ImportState: true,
483+
ImportStateVerify: true,
484+
ImportStateVerifyIgnore: []string{"ip_range", "org_id"},
485+
},
486+
},
487+
})
488+
}
489+
490+
func testAccApigeeInstance_apigeeInstanceServiceAttachmentBasicTestExample(context map[string]interface{}) string {
491+
return Nprintf(`
492+
resource "google_project" "project" {
493+
project_id = "tf-test%{random_suffix}"
494+
name = "tf-test%{random_suffix}"
495+
org_id = "%{org_id}"
496+
billing_account = "%{billing_account}"
497+
}
498+
499+
resource "google_project_service" "apigee" {
500+
project = google_project.project.project_id
501+
service = "apigee.googleapis.com"
502+
}
503+
504+
resource "google_project_service" "compute" {
505+
project = google_project.project.project_id
506+
service = "compute.googleapis.com"
507+
}
508+
509+
resource "google_project_service" "servicenetworking" {
510+
project = google_project.project.project_id
511+
service = "servicenetworking.googleapis.com"
512+
}
513+
514+
resource "google_compute_network" "apigee_network" {
515+
name = "apigee-network"
516+
project = google_project.project.project_id
517+
depends_on = [google_project_service.compute]
518+
}
519+
520+
resource "google_compute_global_address" "apigee_range" {
521+
name = "apigee-range"
522+
purpose = "VPC_PEERING"
523+
address_type = "INTERNAL"
524+
prefix_length = 16
525+
network = google_compute_network.apigee_network.id
526+
project = google_project.project.project_id
527+
}
528+
529+
resource "google_service_networking_connection" "apigee_vpc_connection" {
530+
network = google_compute_network.apigee_network.id
531+
service = "servicenetworking.googleapis.com"
532+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
533+
depends_on = [google_project_service.servicenetworking]
534+
}
535+
536+
resource "google_compute_address" "psc_ilb_consumer_address" {
537+
name = "psc-ilb-consumer-address"
538+
region = "us-west2"
539+
540+
subnetwork = "default"
541+
address_type = "INTERNAL"
542+
543+
project = google_project.project.project_id
544+
depends_on = [google_project_service.compute]
545+
}
546+
547+
resource "google_compute_forwarding_rule" "psc_ilb_consumer" {
548+
name = "psc-ilb-consumer-forwarding-rule"
549+
region = "us-west2"
550+
551+
target = google_compute_service_attachment.psc_ilb_service_attachment.id
552+
load_balancing_scheme = "" # need to override EXTERNAL default when target is a service attachment
553+
network = "default"
554+
ip_address = google_compute_address.psc_ilb_consumer_address.id
555+
556+
project = google_project.project.project_id
557+
}
558+
559+
resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
560+
name = "producer-forwarding-rule"
561+
region = "us-west2"
562+
563+
load_balancing_scheme = "INTERNAL"
564+
backend_service = google_compute_region_backend_service.producer_service_backend.id
565+
all_ports = true
566+
network = google_compute_network.psc_ilb_network.name
567+
subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
568+
569+
project = google_project.project.project_id
570+
}
571+
572+
resource "google_compute_region_backend_service" "producer_service_backend" {
573+
name = "producer-service"
574+
region = "us-west2"
575+
576+
health_checks = [google_compute_health_check.producer_service_health_check.id]
577+
578+
project = google_project.project.project_id
579+
}
580+
581+
resource "google_compute_health_check" "producer_service_health_check" {
582+
name = "producer-service-health-check"
583+
584+
check_interval_sec = 1
585+
timeout_sec = 1
586+
tcp_health_check {
587+
port = "80"
588+
}
589+
590+
project = google_project.project.project_id
591+
depends_on = [google_project_service.compute]
592+
}
593+
594+
resource "google_compute_network" "psc_ilb_network" {
595+
name = "psc-ilb-network"
596+
auto_create_subnetworks = false
597+
598+
project = google_project.project.project_id
599+
depends_on = [google_project_service.compute]
600+
}
601+
602+
resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
603+
name = "psc-ilb-producer-subnetwork"
604+
region = "us-west2"
605+
606+
network = google_compute_network.psc_ilb_network.id
607+
ip_cidr_range = "10.0.0.0/16"
608+
609+
project = google_project.project.project_id
610+
}
611+
612+
resource "google_compute_subnetwork" "psc_ilb_nat" {
613+
name = "psc-ilb-nat"
614+
region = "us-west2"
615+
616+
network = google_compute_network.psc_ilb_network.id
617+
purpose = "PRIVATE_SERVICE_CONNECT"
618+
ip_cidr_range = "10.1.0.0/16"
619+
620+
project = google_project.project.project_id
621+
}
622+
623+
resource "google_compute_service_attachment" "psc_ilb_service_attachment" {
624+
name = "my-psc-ilb"
625+
region = "us-west2"
626+
description = "A service attachment configured with Terraform"
627+
628+
enable_proxy_protocol = true
629+
connection_preference = "ACCEPT_AUTOMATIC"
630+
nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
631+
target_service = google_compute_forwarding_rule.psc_ilb_target_service.id
632+
633+
project = google_project.project.project_id
634+
}
635+
636+
resource "google_apigee_organization" "apigee_org" {
637+
analytics_region = "us-central1"
638+
project_id = google_project.project.project_id
639+
authorized_network = google_compute_network.apigee_network.id
640+
depends_on = [
641+
google_service_networking_connection.apigee_vpc_connection,
642+
google_project_service.apigee,
643+
]
644+
}
645+
646+
resource "google_apigee_instance" "apigee_instance" {
647+
name = "tf-test%{random_suffix}"
648+
location = "us-central1"
649+
org_id = google_apigee_organization.apigee_org.id
650+
consumer_accept_list = [123456, google_project.project.number]
651+
}
652+
`, context)
653+
}
654+
462655
func testAccCheckApigeeInstanceDestroyProducer(t *testing.T) func(s *terraform.State) error {
463656
return func(s *terraform.State) error {
464657
for name, rs := range s.RootModule().Resources {

website/docs/r/apigee_instance.html.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ The following arguments are supported:
271271
Customer Managed Encryption Key (CMEK) used for disk and volume encryption. Required for Apigee paid subscriptions only.
272272
Use the following format: `projects/([^/]+)/locations/([^/]+)/keyRings/([^/]+)/cryptoKeys/([^/]+)`
273273

274+
* `consumer_accept_list` -
275+
(Optional)
276+
Optional. Customer accept list represents the list of projects (id/number) on customer
277+
side that can privately connect to the service attachment. It is an optional field
278+
which the customers can provide during the instance creation. By default, the customer
279+
project associated with the Apigee organization will be included to the list.
280+
274281

275282
## Attributes Reference
276283

@@ -284,6 +291,11 @@ In addition to the arguments listed above, the following computed attributes are
284291
* `port` -
285292
Output only. Port number of the exposed Apigee endpoint.
286293

294+
* `service_attachment` -
295+
Output only. Resource name of the service attachment created for the instance in
296+
the format: projects/*/regions/*/serviceAttachments/* Apigee customers can privately
297+
forward traffic to this service attachment using the PSC endpoints.
298+
287299

288300
## Timeouts
289301

0 commit comments

Comments
 (0)