diff --git a/modules/project_services/examples/project_services/README.md b/examples/project_services/README.md similarity index 72% rename from modules/project_services/examples/project_services/README.md rename to examples/project_services/README.md index 23afbda5..02804899 100755 --- a/modules/project_services/examples/project_services/README.md +++ b/examples/project_services/README.md @@ -11,7 +11,7 @@ Expected variables: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| credentials\_path | Path to a service account credentials file with rights to run the Project Factory. If this file is absent Terraform will fall back to Application Default Credentials. | string | `""` | no | +| enable | Actually enable the APIs listed | string | `"true"` | no | | project\_id | The GCP project you want to enable APIs on | string | n/a | yes | ## Outputs diff --git a/modules/project_services/examples/project_services/main.tf b/examples/project_services/main.tf similarity index 70% rename from modules/project_services/examples/project_services/main.tf rename to examples/project_services/main.tf index 24682f15..9ec44f2a 100755 --- a/modules/project_services/examples/project_services/main.tf +++ b/examples/project_services/main.tf @@ -14,32 +14,25 @@ * limitations under the License. */ -locals { - credentials_file_path = var.credentials_path -} - /****************************************** Provider configuration *****************************************/ provider "google" { - credentials = file(local.credentials_file_path) - version = "~> 2.18.1" + version = "~> 2.18.1" } provider "google-beta" { - credentials = file(local.credentials_file_path) - version = "~> 2.18.1" + version = "~> 2.18.1" } module "project-services" { - source = "../../../../modules/project_services" + source = "../../modules/project_services" project_id = var.project_id - enable_apis = "true" + enable_apis = var.enable disable_services_on_destroy = "true" activate_apis = [ - "compute.googleapis.com", - "iam.googleapis.com", + "sqladmin.googleapis.com", + "bigquery-json.googleapis.com", ] } - diff --git a/modules/project_services/examples/project_services/outputs.tf b/examples/project_services/outputs.tf similarity index 99% rename from modules/project_services/examples/project_services/outputs.tf rename to examples/project_services/outputs.tf index 90dc6416..bab07553 100755 --- a/modules/project_services/examples/project_services/outputs.tf +++ b/examples/project_services/outputs.tf @@ -18,4 +18,3 @@ output "project_id" { value = module.project-services.project_id description = "The GCP project you want to enable APIs on" } - diff --git a/modules/project_services/examples/project_services/variables.tf b/examples/project_services/variables.tf similarity index 74% rename from modules/project_services/examples/project_services/variables.tf rename to examples/project_services/variables.tf index b516614e..ce1d5a30 100755 --- a/modules/project_services/examples/project_services/variables.tf +++ b/examples/project_services/variables.tf @@ -14,12 +14,11 @@ * limitations under the License. */ -variable "credentials_path" { - description = "Path to a service account credentials file with rights to run the Project Factory. If this file is absent Terraform will fall back to Application Default Credentials." - default = "" -} - variable "project_id" { description = "The GCP project you want to enable APIs on" } +variable "enable" { + description = "Actually enable the APIs listed" + default = true +} diff --git a/modules/project_services/main.tf b/modules/project_services/main.tf index 72bf03e1..8859ae42 100644 --- a/modules/project_services/main.tf +++ b/modules/project_services/main.tf @@ -14,11 +14,15 @@ * limitations under the License. */ +locals { + api_set = var.enable_apis ? toset(var.activate_apis) : [] +} + /****************************************** APIs configuration *****************************************/ resource "google_project_service" "project_services" { - for_each = toset([for api in var.activate_apis : api if var.enable_apis]) + for_each = local.api_set project = var.project_id service = each.value disable_on_destroy = var.disable_services_on_destroy diff --git a/modules/project_services/outputs.tf b/modules/project_services/outputs.tf index 7ea9df23..bbadc86d 100644 --- a/modules/project_services/outputs.tf +++ b/modules/project_services/outputs.tf @@ -16,9 +16,5 @@ output "project_id" { description = "The GCP project you want to enable APIs on" - value = element( - [for v in google_project_service.project_services : v.project], - 0, - ) + value = var.enable_apis ? element([for v in google_project_service.project_services : v.project], 0) : var.project_id } -