-
Notifications
You must be signed in to change notification settings - Fork 543
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
Adding new App Engine support #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# App Engine Project | ||
|
||
This example illustrates how to create a simple project with App Engine enabled. | ||
|
||
It will do the following: | ||
- Create a project | ||
- Active the Google App Engine Admin API on the new project | ||
- Create a new App Engine app | ||
|
||
Expected variables: | ||
- `admin_email` | ||
- `organization_id` | ||
- `billing_account` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
credentials_file_path = "${path.module}/sa-key.json" | ||
} | ||
|
||
/****************************************** | ||
Provider configuration | ||
*****************************************/ | ||
provider "gsuite" { | ||
credentials = "${file(local.credentials_file_path)}" | ||
impersonated_user_email = "${var.admin_email}" | ||
} | ||
|
||
module "project-factory" { | ||
source = "../../" | ||
random_project_id = "true" | ||
name = "appeng-sample" | ||
org_id = "${var.organization_id}" | ||
billing_account = "${var.billing_account}" | ||
credentials_path = "${local.credentials_file_path}" | ||
|
||
app_engine { | ||
location_id = "us-central" | ||
|
||
feature_settings = [ | ||
{ | ||
split_health_checks = true | ||
}, | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "project_info_example" { | ||
value = "${module.project-factory.project_id}" | ||
description = "The ID of the created project" | ||
} | ||
|
||
output "domain_example" { | ||
value = "${module.project-factory.domain}" | ||
description = "The organization's domain" | ||
} | ||
|
||
output "app_engine_enabled_example" { | ||
value = "${module.project-factory.app_engine_enabled}" | ||
description = "Whether app engine is enabled" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "admin_email" { | ||
description = "Admin user email on Gsuite" | ||
} | ||
|
||
variable "organization_id" { | ||
description = "The organization id for the associated services" | ||
} | ||
|
||
variable "billing_account" { | ||
description = "The ID of the billing account to associate this project with" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,12 @@ locals { | |
project_bucket_name = "${var.bucket_name != "" ? var.bucket_name : format("%s-state", var.name)}" | ||
create_bucket = "${var.bucket_project != "" ? "true" : "false"}" | ||
gsuite_group = "${var.group_name != "" || var.create_group}" | ||
app_engine_enabled = "${length(keys(var.app_engine)) > 0 ? true : false}" | ||
|
||
app_engine_config = { | ||
enabled = "${list(var.app_engine)}" | ||
disabled = "${list()}" | ||
} | ||
} | ||
|
||
/****************************************** | ||
|
@@ -76,6 +82,8 @@ resource "google_project" "project" { | |
auto_create_network = "${var.auto_create_network}" | ||
|
||
labels = "${var.labels}" | ||
|
||
app_engine = "${local.app_engine_config["${local.app_engine_enabled ? "enabled" : "disabled"}"]}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ryanckoch This is hard to parse and somewhat confusing. Wouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wont allow for a list in a conditional. That would definitely be much cleaner, but that is the reason for the hack app_engine_config map. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also worth noting, that although the examples in the documentation show app_engine as accepting a map, it accepts a list with a max length of 1. Have created an issue on the provider: hashicorp/terraform-provider-google#1821 |
||
} | ||
|
||
/****************************************** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,24 @@ | |
[[ "$output" =~ 0\ destroyed ]] | ||
} | ||
|
||
@test "Terraform plan setting of App Engine settings" { | ||
|
||
run terraform plan | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ 0\ to\ add ]] | ||
[[ "$output" =~ 1\ to\ change ]] | ||
[[ "$output" =~ 0\ to\ destroy ]] | ||
} | ||
|
||
@test "Terraform apply" { | ||
|
||
run terraform apply -auto-approve | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ 0\ added ]] | ||
[[ "$output" =~ 1\ changed ]] | ||
[[ "$output" =~ 0\ destroyed ]] | ||
} | ||
|
||
# #################################### # | ||
# gcloud tests # | ||
# #################################### # | ||
|
@@ -49,14 +67,18 @@ | |
[[ "${lines[5]}" = "projectId: $PROJECT_ID" ]] | ||
} | ||
|
||
@test "Test the compute api must be activated" { | ||
@test "Test the correct apis are activated" { | ||
|
||
export PROJECT_ID="$(terraform output project_info_example)" | ||
export GROUP_EMAIL="$(terraform output group_email_example)" | ||
|
||
run gcloud services list | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[1]}" = *"compute.googleapis.com"* ]] | ||
[[ "${lines[2]}" = *"compute.googleapis.com"* ]] | ||
|
||
run gcloud services list | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[1]}" = *"appengine.googleapis.com"* ]] | ||
} | ||
|
||
@test "Test that project has the shared vpc associated (host project)" { | ||
|
@@ -69,25 +91,16 @@ | |
[[ "${lines[1]}" = "$SHARED_VPC" ]] | ||
} | ||
|
||
@test "Test project has the service account created" { | ||
|
||
export PROJECT_ID="$(terraform output project_info_example)" | ||
export GROUP_EMAIL="$(terraform output group_email_example)" | ||
|
||
run gcloud iam service-accounts list --format=list | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[1]}" = " email: project-service-account@$PROJECT_ID.iam.gserviceaccount.com" ]] | ||
} | ||
|
||
@test "Test project has not the default service account" { | ||
@test "Test project has only the expected service accounts" { | ||
|
||
export PROJECT_ID="$(terraform output project_info_example)" | ||
export GROUP_EMAIL="$(terraform output group_email_example)" | ||
|
||
run gcloud iam service-accounts list | ||
run gcloud iam service-accounts list --format="get(email)" | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[1]}" =~ project-service-account@$PROJECT_ID.iam.gserviceaccount.com ]] | ||
[[ "${lines[2]}" = "" ]] | ||
[[ "${lines[0]}" = "[email protected]" ]] | ||
[[ "${lines[1]}" = "project-service-account@$PROJECT_ID.iam.gserviceaccount.com" ]] | ||
[[ "${lines[3]}" = "" ]] | ||
} | ||
|
||
@test "Test Gsuite group $GROUP_EMAIL has role:$GROUP_ROLE on project" { | ||
|
@@ -132,6 +145,21 @@ | |
[[ "$output" = *"{u'role': u'roles/compute.networkUser', u'members': [u'group:$GROUP_EMAIL', u'serviceAccount:project-service-account@$PROJECT_ID.iam.gserviceaccount.com']}"* ]] | ||
} | ||
|
||
@test "Test App Engine app created with the correct settings" { | ||
|
||
PROJECT_ID="$(terraform output project_info_example)" | ||
AUTH_DOMAIN="$(echo $GSUITE_ADMIN_ACCOUNT | cut -d '@' -f2)" | ||
|
||
run gcloud --project=${PROJECT_ID} app describe | ||
[ "$status" -eq 0 ] | ||
[[ "${lines[0]}" = "authDomain: $AUTH_DOMAIN" ]] | ||
[[ "${lines[4]}" = "featureSettings: {}" ]] | ||
[[ "${lines[6]}" = "id: $PROJECT_ID}" ]] | ||
[[ "${lines[7]}" = "name: apps/$PROJECT_ID" ]] | ||
[[ "${lines[8]}" = "locationId: $REGION" ]] | ||
[[ "${lines[9]}" = "servingStatus: SERVING" ]] | ||
} | ||
|
||
# #################################### # | ||
# Terraform destroy test # | ||
# #################################### # | ||
|
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.
Does this actually work? var.app_engine is a map, not a list.
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 gets the length of keys in app_engine which is a list
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.
But then I'm confused about how line 86 works? https://github.com/terraform-google-modules/terraform-google-project-factory/pull/4/files/a51eb1f65e51143af5b7dff92d9ce2fa268cfb38#diff-7a370d8342e7203b805911c92454f0f4R86
Where do we actually pass in the keys from the map?
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.
local.app_engine_config is a map of lists with keys
enabled
anddisabled
. Line 86 is referencing that list by key depending if local.app_engine_enabled is true or false. If local.app_engine_enabled is true, it setsapp_engine
to theenabled
list which is the users config, otherwise it uses thedisabled
list which is empty. It is a dirty hack, but the only way I could see to pass a completely empty list toapp_engine
and still be able to accept theapp_engine
variable as a map in our module. Otherwise, it would setapp_engine = [{}]
which isnt an empty list and tells the provider to setill enable app_engine.