Skip to content

Commit

Permalink
Apigee Nat Address Resource (GoogleCloudPlatform#5018)
Browse files Browse the repository at this point in the history
  • Loading branch information
danistrebel authored Dec 22, 2021
1 parent 520ec94 commit ed44493
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 1 deletion.
58 changes: 57 additions & 1 deletion mmv1/products/apigee/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ objects:
name: 'instanceId'
description: |
The Apigee instance associated with the Apigee environment,
in the format `organisations/{{org_name}}/instances/{{instance_name}}`.
in the format `organizations/{{org_name}}/instances/{{instance_name}}`.
required: true
url_param_only: true
properties:
Expand Down Expand Up @@ -420,3 +420,59 @@ objects:
'Creating an environment':
'https://cloud.google.com/apigee/docs/api-platform/get-started/create-environment'
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.envgroups.attachments/create'
- !ruby/object:Api::Resource
name: 'NatAddress'
base_url: '{{instance_id}}/natAddresses'
create_url: '{{instance_id}}/natAddresses'
delete_url: '{{instance_id}}/natAddresses/{{name}}'
self_link: '{{instance_id}}/natAddresses/{{name}}'
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: 'name'
base_url: '{{op_id}}'
wait_ms: 1000
result: !ruby/object:Api::OpAsync::Result
path: 'response'
resource_inside_response: true
status: !ruby/object:Api::OpAsync::Status
path: 'done'
complete: True
allowed:
- True
- False
error: !ruby/object:Api::OpAsync::Error
path: 'error'
message: 'message'
input: true
description: |
Apigee NAT (network address translation) address. A NAT address is a static external IP address used for Internet egress traffic. This is not avaible for Apigee hybrid.
Apigee NAT addresses are not automatically activated because they might require explicit allow entries on the target systems first. See https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.instances.natAddresses/activate
parameters:
- !ruby/object:Api::Type::String
name: 'instanceId'
description: |
The Apigee instance associated with the Apigee environment,
in the format `organizations/{{org_name}}/instances/{{instance_name}}`.
required: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
Resource ID of the NAT address.
required: true
- !ruby/object:Api::Type::String
name: 'ipAddress'
description: |
The allocated NAT IP address.
output: true
- !ruby/object:Api::Type::String
name: 'state'
description: |
State of the NAT IP address.
output: true
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Provisioning NAT IPs':
'https://cloud.google.com/apigee/docs/api-platform/security/nat-provisioning'
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.instances.natAddresses'
25 changes: 25 additions & 0 deletions mmv1/products/apigee/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,31 @@ overrides: !ruby/object:Overrides::ResourceOverrides
delete_minutes: 30
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/apigee_environment_group_attachment.go.erb
'NatAddress': !ruby/object:Overrides::Terraform::ResourceOverride
autogen_async: true
import_format: ["{{instance_id}}/natAddresses/{{name}}", "{{instance_id}}/{{name}}"]
delete_url: '{{instance_id}}/natAddresses/{{name}}'
skip_sweeper: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "apigee_nat_address_basic"
skip_test: true
- !ruby/object:Provider::Terraform::Examples
# This is a more verbose version of the above that creates all
# the resources needed for the acceptance test.
name: "apigee_nat_address_basic_test"
primary_resource_id: "apigee_nat_address"
test_env_vars:
org_id: :ORG_ID
billing_account: :BILLING_ACCT
skip_docs: true
# Resource creation race
skip_vcr: true
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 30
delete_minutes: 30
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/apigee_nat_address.go.erb
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
# This is usually to add licensing info, autogeneration notices, etc.
Expand Down
18 changes: 18 additions & 0 deletions mmv1/templates/terraform/custom_import/apigee_nat_address.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
config := meta.(*Config)

// current import_formats cannot import fields with forward slashes in their value
if err := parseImportId([]string{
"(?P<instance_id>.+)/natAddresses/(?P<name>.+)",
"(?P<instance_id>.+)/(?P<name>.+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{instance_id}}/natAddresses/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
36 changes: 36 additions & 0 deletions mmv1/templates/terraform/examples/apigee_nat_address_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
data "google_client_config" "current" {}

resource "google_compute_network" "apigee_network" {
name = "apigee-network"
}

resource "google_compute_global_address" "apigee_range" {
name = "apigee-range"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.apigee_network.id
}

resource "google_service_networking_connection" "apigee_vpc_connection" {
network = google_compute_network.apigee_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
}

resource "google_apigee_organization" "apigee_org" {
analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
}

resource "google_apigee_instance" "apigee_instance" {
name = "tf-test%{random_suffix}"
location = "us-central1-b"
org_id = google_apigee_organization.apigee_org.id
}

resource "google_apigee_nat_address" "apigee_nat_addres" {
instance_id = google_apigee_instance.apigee_instance.id
name = "nat-address"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>"
}

resource "google_project_service" "apigee" {
project = google_project.project.project_id
service = "apigee.googleapis.com"
}

resource "google_project_service" "compute" {
project = google_project.project.project_id
service = "compute.googleapis.com"
}

resource "google_project_service" "servicenetworking" {
project = google_project.project.project_id
service = "servicenetworking.googleapis.com"
}

resource "google_compute_network" "apigee_network" {
name = "apigee-network"
project = google_project.project.project_id
depends_on = [google_project_service.compute]
}

resource "google_compute_global_address" "apigee_range" {
name = "apigee-range"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.apigee_network.id
project = google_project.project.project_id
}

resource "google_service_networking_connection" "apigee_vpc_connection" {
network = google_compute_network.apigee_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
depends_on = [google_project_service.servicenetworking]
}

resource "google_apigee_organization" "apigee_org" {
analytics_region = "us-central1"
project_id = google_project.project.project_id
authorized_network = google_compute_network.apigee_network.id
depends_on = [
google_service_networking_connection.apigee_vpc_connection,
google_project_service.apigee,
]
}

resource "google_apigee_instance" "apigee_instance" {
name = "tf-test%{random_suffix}"
location = "us-central1-b"
org_id = google_apigee_organization.apigee_org.id
}

resource "google_apigee_nat_address" "<%= ctx[:primary_resource_id] %>" {
instance_id = google_apigee_instance.apigee_instance.id
name = "nat-address"
}

0 comments on commit ed44493

Please sign in to comment.