-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added code for Apigee Environments #4553
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
mmv1/templates/terraform/custom_import/apigee_environment.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
config := meta.(*Config) | ||
|
||
// current import_formats cannot import fields with forward slashes in their value | ||
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
nameParts := strings.Split(d.Get("name").(string), "/") | ||
if len(nameParts) == 4 { | ||
// `organizations/{{org_name}}/environments/{{name}}` | ||
orgId := fmt.Sprintf("organizations/%s", nameParts[1]) | ||
if err := d.Set("org_id", orgId); err != nil { | ||
return nil, fmt.Errorf("Error setting org_id: %s", err) | ||
} | ||
if err := d.Set("name", nameParts[3]); err != nil { | ||
return nil, fmt.Errorf("Error setting name: %s", err) | ||
} | ||
} else if len(nameParts) == 3 { | ||
// `organizations/{{org_name}}/{{name}}` | ||
orgId := fmt.Sprintf("organizations/%s", nameParts[1]) | ||
if err := d.Set("org_id", orgId); err != nil { | ||
return nil, fmt.Errorf("Error setting org_id: %s", err) | ||
} | ||
if err := d.Set("name", nameParts[2]); err != nil { | ||
return nil, fmt.Errorf("Error setting name: %s", err) | ||
} | ||
} else { | ||
return nil, fmt.Errorf( | ||
"Saw %s when the name is expected to have shape %s or %s", | ||
d.Get("name"), | ||
"organizations/{{org_name}}/environments/{{name}}", | ||
"organizations/{{org_name}}/{{name}}") | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := replaceVars(d, config, "{{org_id}}/environments/{{name}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
34 changes: 34 additions & 0 deletions
34
mmv1/templates/terraform/examples/apigee_environment_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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 = data.google_client_config.current.project | ||
authorized_network = google_compute_network.apigee_network.id | ||
depends_on = [google_service_networking_connection.apigee_vpc_connection] | ||
} | ||
|
||
resource "google_apigee_environment" "env" { | ||
name = "tf-test%{random_suffix}" | ||
description = "Apigee Environment" | ||
displayName = "environment-1" | ||
org_id = google_apigee_organization.apigee_org.id | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
mmv1/templates/terraform/examples/apigee_environment_basic_test.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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_environment" "<%= ctx[:primary_resource_id] %>" { | ||
org_id = google_apigee_organization.apigee_org.id | ||
name = "tf-test%{random_suffix}" | ||
description = "Apigee Environment" | ||
display_name = "environment-1" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the API docs specify this as
parent
- why doesorgId
work? https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments/createThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parent is just a URL parameter, so we can call it however we want. We actually have the two models in other resources. For example, the older
google_access_context_manager_access_level
used parent as is, while the newergoogle_kms_crypto_key
uses the parent askey_ring
. The second (with an explicit field name that matches what is expected) seems more readable.