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

Commit

Permalink
Feature/support bigtable (#209)
Browse files Browse the repository at this point in the history
* support bigtable

* update bucket name

* update dependancies

* update readme

* update reference
  • Loading branch information
ericyz authored Apr 7, 2021
1 parent 811d32c commit 8362224
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The follow Terraform resources are supported for running validation checks:

```
google_bigquery_dataset
google_bigtable_instance
google_compute_disk
google_compute_forwarding_rule
google_compute_global_forwarding_rule
Expand Down
8 changes: 8 additions & 0 deletions converters/google/mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func mappers() map[string][]mapper {
{convert: converter.GetProjectBillingInfoCaiObject},
},

"google_bigtable_instance": {
{
convert: converter.GetBigtableInstanceCaiObject,
},
{
convert: converter.GetBigtableClusterCaiObject,
},
},
// Terraform IAM policy resources have a N:1 relationship with CAI assets.
"google_organization_iam_policy": {
{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/GoogleCloudPlatform/terraform-validator

require (
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210324165518-542d60abac29
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210406210412-d3254d3ece4e
github.com/forseti-security/config-validator v0.0.0-20200812033229-7388761cc9ca
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.4.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210318171059
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210318171059-9ab40040d220/go.mod h1:ZmY0Ua5EVNaxHXJe5x3VQfaghzCmORy2fksFH4Wf6Eg=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210319162701-45d07ba9aed4 h1:mnfuVLq9UEYOi3ERSLH9PwV9JCJA+pe0hnlOvhS1roc=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210319162701-45d07ba9aed4/go.mod h1:ZmY0Ua5EVNaxHXJe5x3VQfaghzCmORy2fksFH4Wf6Eg=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210324165518-542d60abac29 h1:TcHoL4qhibgxrwihzVd8T031OXOqKbl83ZNTUyjpMR8=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210324165518-542d60abac29/go.mod h1:ZmY0Ua5EVNaxHXJe5x3VQfaghzCmORy2fksFH4Wf6Eg=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210329172659-48085272153f h1:9x0YMXHGe+prtXe+0Z6yS7CsnHWFD2wDvpg8nw/bjBI=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210329172659-48085272153f/go.mod h1:ZmY0Ua5EVNaxHXJe5x3VQfaghzCmORy2fksFH4Wf6Eg=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210406210412-d3254d3ece4e h1:p8KBvzXl227Q8EHWdiPTq4JjyBsD2f5Kma7BHxkueTk=
github.com/GoogleCloudPlatform/terraform-google-conversion v0.0.0-20210406210412-d3254d3ece4e/go.mod h1:ZmY0Ua5EVNaxHXJe5x3VQfaghzCmORy2fksFH4Wf6Eg=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down
1 change: 1 addition & 0 deletions test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestCLI(t *testing.T) {
{name: "instance"},
{name: "sql"},
{name: "example_bigquery_dataset"},
{name: "example_bigtable_instance"},
{name: "example_compute_disk"},
{name: "example_compute_firewall"},
{name: "example_compute_forwarding_rule"},
Expand Down
1 change: 1 addition & 0 deletions test/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
name string
}{
{name: "example_bigquery_dataset"},
{name: "example_bigtable_instance"},
{name: "example_compute_disk"},
{name: "example_compute_firewall"},
{name: "example_compute_instance"},
Expand Down
36 changes: 36 additions & 0 deletions testdata/templates/example_bigtable_instance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"name": "//bigtable.googleapis.com/projects/{{.Provider.project}}/instances/tf-instance",
"asset_type": "bigtableadmin.googleapis.com/Instance",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v1",
"discovery_document_uri": "https://bigtableadmin.googleapis.com/$discovery/rest",
"discovery_name": "Instance",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"labels": {
"test-name": "test-value"
},
"name": "projects/{{.Provider.project}}/instances/tf-instance"
}
}
},
{
"name": "//bigtable.googleapis.com/projects/{{.Provider.project}}/instances/tf-instance/clusters/placeholder-foobar",
"asset_type": "bigtableadmin.googleapis.com/Cluster",
"ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
"resource": {
"version": "v2",
"discovery_document_uri": "https://bigtableadmin.googleapis.com/$discovery/rest",
"discovery_name": "Cluster",
"parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
"data": {
"defaultStorageType": "HDD",
"location": "australia-southeast1-a",
"name": "projects/{{.Provider.project}}/instances/tf-instance/clusters/tf-instance-cluster",
"serverNodes": 1
}
}
}
]
43 changes: 43 additions & 0 deletions testdata/templates/example_bigtable_instance.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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_bigtable_instance" "test" {
name = "tf-instance"

cluster {
cluster_id = "tf-instance-cluster"
num_nodes = 1
storage_type = "HDD"
zone = "australia-southeast1-a"
}

labels = {
test-name = "test-value"
}
}
124 changes: 124 additions & 0 deletions testdata/templates/example_bigtable_instance.tfplan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"format_version": "0.1",
"terraform_version": "0.13.5",
"planned_values": {
"root_module": {
"resources": [
{
"address": "google_bigtable_instance.test",
"mode": "managed",
"type": "google_bigtable_instance",
"name": "test",
"provider_name": "registry.terraform.io/hashicorp/google",
"schema_version": 1,
"values": {
"cluster": [
{
"cluster_id": "tf-instance-cluster",
"num_nodes": 1,
"storage_type": "HDD",
"zone": "australia-southeast1-a"
}
],
"deletion_protection": true,
"instance_type": "PRODUCTION",
"labels": {
"test-name": "test-value"
},
"name": "tf-instance"
}
}
]
}
},
"resource_changes": [
{
"address": "google_bigtable_instance.test",
"mode": "managed",
"type": "google_bigtable_instance",
"name": "test",
"provider_name": "registry.terraform.io/hashicorp/google",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"cluster": [
{
"cluster_id": "tf-instance-cluster",
"num_nodes": 1,
"storage_type": "HDD",
"zone": "australia-southeast1-a"
}
],
"deletion_protection": true,
"instance_type": "PRODUCTION",
"labels": {
"test-name": "test-value"
},
"name": "tf-instance"
},
"after_unknown": {
"cluster": [
{}
],
"display_name": true,
"id": true,
"labels": {},
"project": true
}
}
}
],
"configuration": {
"provider_config": {
"google": {
"name": "google",
"expressions": {
"project": {
"constant_value": "{{.Provider.project}}"
}
}
}
},
"root_module": {
"resources": [
{
"address": "google_bigtable_instance.test",
"mode": "managed",
"type": "google_bigtable_instance",
"name": "test",
"provider_config_key": "google",
"expressions": {
"cluster": [
{
"cluster_id": {
"constant_value": "tf-instance-cluster"
},
"num_nodes": {
"constant_value": 1
},
"storage_type": {
"constant_value": "HDD"
},
"zone": {
"constant_value": "australia-southeast1-a"
}
}
],
"labels": {
"constant_value": {
"test-name": "test-value"
}
},
"name": {
"constant_value": "tf-instance"
}
},
"schema_version": 1
}
]
}
}
}

0 comments on commit 8362224

Please sign in to comment.