Skip to content
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

Fix up API services module and example #303

Merged
merged 5 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ output "project_id" {
value = module.project-services.project_id
description = "The GCP project you want to enable APIs on"
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion modules/project_services/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions modules/project_services/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}