2022-08-09 02:21:24 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2022 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.
|
|
|
|
*/
|
|
|
|
|
2022-09-20 00:55:06 -07:00
|
|
|
|
2022-10-06 23:28:05 -07:00
|
|
|
locals {
|
|
|
|
cloudsql_conf = {
|
|
|
|
database_version = "MYSQL_8_0"
|
|
|
|
tier = "db-g1-small"
|
|
|
|
db = "wp-mysql"
|
|
|
|
user = "admin"
|
|
|
|
}
|
2023-08-20 00:44:20 -07:00
|
|
|
iam_roles = [
|
|
|
|
"roles/cloudsql.admin",
|
|
|
|
"roles/cloudsql.client",
|
|
|
|
"roles/cloudsql.instanceUser",
|
|
|
|
"roles/logging.admin",
|
|
|
|
"roles/iam.serviceAccountUser",
|
|
|
|
"roles/iam.serviceAccountTokenCreator"
|
|
|
|
]
|
2022-10-07 06:29:55 -07:00
|
|
|
connector = var.connector == null ? google_vpc_access_connector.connector.0.self_link : var.connector
|
2022-10-07 06:31:15 -07:00
|
|
|
wp_user = "user"
|
|
|
|
wp_pass = var.wordpress_password == null ? random_password.wp_password.result : var.wordpress_password
|
2022-10-06 23:28:05 -07:00
|
|
|
}
|
|
|
|
|
2023-08-20 00:44:20 -07:00
|
|
|
resource "random_password" "wp_password" {
|
|
|
|
length = 8
|
|
|
|
}
|
2022-10-06 23:28:05 -07:00
|
|
|
|
2022-09-20 00:55:06 -07:00
|
|
|
module "project" {
|
2022-08-09 02:21:24 -07:00
|
|
|
source = "../../../../modules/project"
|
|
|
|
name = var.project_id
|
|
|
|
parent = try(var.project_create.parent, null)
|
|
|
|
billing_account = try(var.project_create.billing_account_id, null)
|
|
|
|
project_create = var.project_create != null
|
|
|
|
prefix = var.project_create == null ? null : var.prefix
|
2023-08-20 00:44:20 -07:00
|
|
|
iam = (
|
|
|
|
var.project_create != true || var.admin_principal == null
|
|
|
|
? {}
|
|
|
|
: { for r in local.iam_roles : r => [var.admin_principal] }
|
|
|
|
)
|
|
|
|
iam_bindings_additive = (
|
|
|
|
var.project_create == true || var.admin_principal == null
|
|
|
|
? {}
|
|
|
|
: { for r in local.iam_roles : r => {
|
|
|
|
member = var.admin_principal
|
|
|
|
role = r
|
|
|
|
} }
|
|
|
|
)
|
2022-08-09 02:21:24 -07:00
|
|
|
services = [
|
|
|
|
"run.googleapis.com",
|
|
|
|
"logging.googleapis.com",
|
|
|
|
"monitoring.googleapis.com",
|
|
|
|
"sqladmin.googleapis.com",
|
|
|
|
"sql-component.googleapis.com",
|
2022-09-09 01:17:47 -07:00
|
|
|
"vpcaccess.googleapis.com",
|
|
|
|
"servicenetworking.googleapis.com"
|
2022-08-09 02:21:24 -07:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-09-20 00:55:06 -07:00
|
|
|
module "cloud_run" {
|
2022-08-09 02:21:24 -07:00
|
|
|
source = "../../../../modules/cloud-run"
|
|
|
|
project_id = module.project.project_id
|
2022-11-23 02:09:00 -08:00
|
|
|
name = "${var.prefix}-cr-wordpress"
|
2022-08-31 07:29:16 -07:00
|
|
|
region = var.region
|
2023-08-20 00:44:20 -07:00
|
|
|
containers = {
|
|
|
|
wp = {
|
|
|
|
image = var.wordpress_image
|
|
|
|
ports = {
|
|
|
|
http = { container_port = var.wordpress_port }
|
|
|
|
}
|
2022-09-20 00:55:06 -07:00
|
|
|
env = {
|
2023-08-20 00:44:20 -07:00
|
|
|
APACHE_HTTP_PORT_NUMBER = var.wordpress_port
|
|
|
|
WORDPRESS_DATABASE_HOST = module.cloudsql.ip
|
|
|
|
WORDPRESS_DATABASE_NAME = local.cloudsql_conf.db
|
|
|
|
WORDPRESS_DATABASE_USER = local.cloudsql_conf.user
|
|
|
|
WORDPRESS_DATABASE_PASSWORD = (
|
|
|
|
var.cloudsql_password == null
|
|
|
|
? module.cloudsql.user_passwords[local.cloudsql_conf.user]
|
|
|
|
: var.cloudsql_password
|
|
|
|
)
|
|
|
|
WORDPRESS_USERNAME = local.wp_user
|
|
|
|
WORDPRESS_PASSWORD = local.wp_pass
|
2022-08-09 02:21:24 -07:00
|
|
|
}
|
|
|
|
}
|
2023-08-20 00:44:20 -07:00
|
|
|
}
|
2022-08-09 02:21:24 -07:00
|
|
|
iam = {
|
2022-08-31 07:29:16 -07:00
|
|
|
"roles/run.invoker" : [var.cloud_run_invoker]
|
2022-08-09 02:21:24 -07:00
|
|
|
}
|
2022-08-31 07:19:54 -07:00
|
|
|
revision_annotations = {
|
|
|
|
autoscaling = {
|
|
|
|
min_scale = 1
|
|
|
|
max_scale = 2
|
|
|
|
}
|
|
|
|
# connect to CloudSQL
|
2023-08-20 00:44:20 -07:00
|
|
|
cloudsql_instances = [module.cloudsql.connection_name]
|
2022-09-20 00:55:06 -07:00
|
|
|
# allow all traffic
|
2022-10-07 06:29:55 -07:00
|
|
|
vpcaccess_connector = local.connector
|
2023-08-20 00:44:20 -07:00
|
|
|
vpcaccess_egress = "all-traffic"
|
2022-08-31 07:19:54 -07:00
|
|
|
}
|
|
|
|
ingress_settings = "all"
|
2022-11-23 02:09:00 -08:00
|
|
|
}
|