Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Add support for google_compute_network and google_compute_subnetwork (#…
Browse files Browse the repository at this point in the history
…221)

* Upgrade Terraform version to `0.12.24` in order to pass the `TestCLI/v=0.12/tf=example_project_update/offline=false` and `TestCLI/v=0.12/tf=example_project_update/offline=true` tests, because those tests use a test `.tfstate` file based on `0.12.24`.

* Implement support for the `google_compute_network` resource type.

* Implement support for the `google_compute_subnetwork` resource type.

* Add the google_compute_network CAI assets, now that `terraform-validator` can convert them.
  • Loading branch information
jday29 committed Jun 8, 2021
1 parent d31d197 commit 5d3de04
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM golang:1.14
RUN apt-get update && apt-get -y install wget unzip

WORKDIR /tmp
RUN wget https://releases.hashicorp.com/terraform/0.12.20/terraform_0.12.20_linux_amd64.zip && unzip terraform_0.12.20_linux_amd64.zip -d /usr/local/bin
RUN wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip && unzip terraform_0.12.24_linux_amd64.zip -d /usr/local/bin


ENV GO111MODULE=on
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ google_compute_forwarding_rule
google_compute_global_forwarding_rule
google_compute_firewall
google_compute_instance
google_compute_network
google_compute_subnetwork
google_container_cluster
google_container_node_pool
google_filestore_instance
Expand Down
2 changes: 2 additions & 0 deletions converters/google/mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func mappers() map[string][]mapper {
"google_compute_forwarding_rule": {{convert: converter.GetComputeForwardingRuleCaiObject}},
"google_compute_global_forwarding_rule": {{convert: converter.GetComputeGlobalForwardingRuleCaiObject}},
"google_compute_instance": {{convert: converter.GetComputeInstanceCaiObject}},
"google_compute_network": {{convert: converter.GetComputeNetworkCaiObject}},
"google_compute_subnetwork": {{convert: converter.GetComputeSubnetworkCaiObject}},
"google_storage_bucket": {{convert: converter.GetStorageBucketCaiObject}},
"google_sql_database_instance": {{convert: converter.GetSQLDatabaseInstanceCaiObject}},
"google_container_cluster": {{convert: converter.GetContainerClusterCaiObject}},
Expand Down
2 changes: 2 additions & 0 deletions test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func TestCLI(t *testing.T) {
{name: "example_compute_firewall"},
{name: "example_compute_forwarding_rule"},
{name: "example_compute_instance"},
{name: "example_compute_network"},
{name: "example_compute_subnetwork"},
{name: "example_compute_global_forwarding_rule"},
{name: "example_container_cluster"},
{name: "example_filestore_instance"},
Expand Down
2 changes: 2 additions & 0 deletions test/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
{name: "example_compute_disk"},
{name: "example_compute_firewall"},
{name: "example_compute_instance"},
{name: "example_compute_network"},
{name: "example_compute_subnetwork"},
{name: "example_compute_forwarding_rule"},
{name: "example_compute_global_forwarding_rule"},
{name: "example_container_cluster"},
Expand Down
15 changes: 15 additions & 0 deletions testdata/templates/example_compute_firewall.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,20 @@
]
}
}
},
{
"name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/test-network",
"asset_type": "compute.googleapis.com/Network",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v1",
"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
"discovery_name": "Network",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"autoCreateSubnetworks": true,
"name": "test-network"
}
}
}
]
17 changes: 17 additions & 0 deletions testdata/templates/example_compute_network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/test-network",
"asset_type": "compute.googleapis.com/Network",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v1",
"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
"discovery_name": "Network",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"autoCreateSubnetworks": false,
"name": "test-network"
}
}
}
]
33 changes: 33 additions & 0 deletions testdata/templates/example_compute_network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2019 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.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> {{.Provider.version}}"
}
}
}

provider "google" {
{{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
}

resource "google_compute_network" "default" {
name = "test-network"
auto_create_subnetworks = false
}
87 changes: 87 additions & 0 deletions testdata/templates/example_compute_network.tfplan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"format_version": "0.1",
"terraform_version": "0.12.24",
"planned_values": {
"root_module": {
"resources": [
{
"address": "google_compute_network.default",
"mode": "managed",
"type": "google_compute_network",
"name": "default",
"provider_name": "google",
"schema_version": 0,
"values": {
"auto_create_subnetworks": false,
"delete_default_routes_on_create": false,
"description": null,
"name": "test-network",
"timeouts": null
}
}
]
}
},
"resource_changes": [
{
"address": "google_compute_network.default",
"mode": "managed",
"type": "google_compute_network",
"name": "default",
"provider_name": "google",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"auto_create_subnetworks": false,
"delete_default_routes_on_create": false,
"description": null,
"name": "test-network",
"timeouts": null
},
"after_unknown": {
"gateway_ipv4": true,
"id": true,
"mtu": true,
"project": true,
"routing_mode": true,
"self_link": true
}
}
}
],
"configuration": {
"provider_config": {
"google": {
"name": "google",
"expressions": {
"project": {
"constant_value": "{{.Provider.project}}"
}
}
}
},
"root_module": {
"resources": [
{
"address": "google_compute_network.default",
"mode": "managed",
"type": "google_compute_network",
"name": "default",
"provider_config_key": "google",
"expressions": {
"auto_create_subnetworks": {
"constant_value": false
},
"name": {
"constant_value": "test-network"
}
},
"schema_version": 0
}
]
}
}
}
41 changes: 41 additions & 0 deletions testdata/templates/example_compute_subnetwork.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/test-network",
"asset_type": "compute.googleapis.com/Network",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v1",
"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
"discovery_name": "Network",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"autoCreateSubnetworks": false,
"name": "test-network"
}
}
},
{
"name": "//compute.googleapis.com/projects/{{.Provider.project}}/regions/us-central1/subnetworks/my-test-subnetwork",
"asset_type": "compute.googleapis.com/Subnetwork",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v1",
"discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
"discovery_name": "Subnetwork",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"ipCidrRange": "10.0.0.0/24",
"logConfig": {
"aggregationInterval": "INTERVAL_10_MIN",
"enable": true,
"filterExpr": "true",
"flowSampling": 0.5,
"metadata": "INCLUDE_ALL_METADATA",
"metadataFields": []
},
"name": "my-test-subnetwork",
"region": "projects/{{.Provider.project}}/global/regions/us-central1"
}
}
}
]
46 changes: 46 additions & 0 deletions testdata/templates/example_compute_subnetwork.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2019 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.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> {{.Provider.version}}"
}
}
}

provider "google" {
{{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
}

resource "google_compute_network" "default" {
name = "test-network"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "my-test-subnetwork" {
name = "my-test-subnetwork"
ip_cidr_range = "10.0.0.0/24"
region = "us-central1"
network = google_compute_network.default.id

log_config {
aggregation_interval = "INTERVAL_10_MIN"
flow_sampling = 0.5
metadata = "INCLUDE_ALL_METADATA"
}
}
Loading

0 comments on commit 5d3de04

Please sign in to comment.