Skip to content

Commit

Permalink
New project variable to prevent deletion of default network (#32)
Browse files Browse the repository at this point in the history
* New project variable to prevent deletion of default network

This is a workaround to fix
#31 while the GCP
terraform provider is fixed

* Add TODOs to remove workarounds in the project module

* Fix Cloud Build files
  • Loading branch information
juliocc authored Feb 6, 2020
1 parent 479be4d commit c7ba3f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .ci/cloudbuild.lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


steps:
- name: "python:3-alpine"
- name: "python:3-alpine3.10"
id: "boilerplate"
args: ["/workspace/.ci/scripts/check_boilerplate.py", "/workspace"]
- name: "wata727/tflint"
Expand Down
6 changes: 3 additions & 3 deletions .ci/cloudbuild.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

steps:
- name: python:3-alpine
- name: python:3-alpine3.10
id: prepare
entrypoint: sh
args:
Expand All @@ -25,15 +25,15 @@ steps:
rm terraform_${_TERRAFORM_VERSION}_linux_amd64.zip &&
chmod 755 /builder/home/.local/bin/terraform
# TODO(ludoo): split into two triggers with different filters
- name: python:3-alpine
- name: python:3-alpine3.10
id: test-foundations
entrypoint: pytest
args:
- -v
- tests/foundations
env:
- PATH=/usr/local/bin:/usr/bin:/bin:/builder/home/.local/bin
- name: python:3-alpine
- name: python:3-alpine3.10
id: test-infrastructure
entrypoint: pytest
args:
Expand Down
1 change: 1 addition & 0 deletions modules/project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module "project" {
| *oslogin* | Enable OS Login. | <code title="">bool</code> | | <code title="">false</code> |
| *oslogin_admins* | List of IAM-style identities that will be granted roles necessary for OS Login administrators. | <code title="list&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |
| *oslogin_users* | List of IAM-style identities that will be granted roles necessary for OS Login users. | <code title="list&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |
| *prevent_default_network_deletion* | Prevent deletion of default network. Use this if your organization has skipDefaultNetworkCreation enforced. | <code title="">bool</code> | | <code title="">false</code> |
| *services* | Service APIs to enable. | <code title="list&#40;string&#41;">list(string)</code> | | <code title="">[]</code> |

## Outputs
Expand Down
15 changes: 9 additions & 6 deletions modules/project/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ locals {
}

resource "google_project" "project" {
org_id = local.parent_type == "organizations" ? local.parent_id : ""
folder_id = local.parent_type == "folders" ? local.parent_id : ""
project_id = "${var.prefix}-${var.name}"
name = "${var.prefix}-${var.name}"
billing_account = var.billing_account
auto_create_network = var.auto_create_network
org_id = local.parent_type == "organizations" ? local.parent_id : ""
folder_id = local.parent_type == "folders" ? local.parent_id : ""
project_id = "${var.prefix}-${var.name}"
name = "${var.prefix}-${var.name}"
billing_account = var.billing_account
# TODO: Once terraform-providers/terraform-provider-google#3582 is
# fixed, we remove the condition and just use
# var.auto_create_network
auto_create_network = var.prevent_default_network_deletion ? null : var.auto_create_network
labels = var.labels
}

Expand Down
8 changes: 8 additions & 0 deletions modules/project/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ variable "services" {
type = list(string)
default = []
}

# TODO: Once terraform-providers/terraform-provider-google#3582 is
# fixed, we can remove this variable
variable "prevent_default_network_deletion" {
description = "Prevent deletion of default network (use this if your organization has skipDefaultNetworkCreation enforced)"
type = bool
default = false
}

0 comments on commit c7ba3f4

Please sign in to comment.