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

Add gcp compute router table. Closes #51 #52

Merged
merged 9 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
45 changes: 45 additions & 0 deletions docs/tables/gcp_compute_router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Table: gcp_compute_router

Cloud Router is a fully distributed and managed Google Cloud service that programs custom dynamic routes and scales with network traffic.

## Examples

### Cloud router basic info

```sql
select
name,
bgp_asn,
bgp_advertise_mode
from
gcp_compute_router;
```


### NAT gateway info attached to router

```sql
select
name,
nat ->> 'name' as nat_name,
nat ->> 'enableEndpointIndependentMapping' as enable_endpoint_independent_mapping,
nat ->> 'natIpAllocateOption' as nat_ip_allocate_option,
nat ->> 'sourceSubnetworkIpRangesToNat' as source_subnetwork_ip_ranges_to_nat
from
gcp_compute_router,
jsonb_array_elements(nats) as nat;
```


### List all routers with custom route advertisements

```sql
select
name,
bgp_asn,
bgp_advertise_mode,
bgp_advertised_ip_ranges
from
gcp_compute_router
where bgp_advertise_mode = 'CUSTOM';
```
Empty file.
24 changes: 24 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"bgp_advertise_mode": "CUSTOM",
"bgp_advertised_groups": [
"ALL_SUBNETS"
],
"bgp_advertised_ip_ranges": [
{
"range": "1.2.3.4"
},
{
"range": "6.7.0.0/16"
}
],
"bgp_asn": 64514,
"description": "Test router to verify the table.",
"kind": "compute#router",
"location": "us-east1",
"name": "{{ resourceName }}",
"network": "{{ output.network.value }}",
"project": "{{ output.project_id.value }}",
"self_link": "{{ output.self_link.value }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-get-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, bgp_asn, description, kind, bgp_advertise_mode, bgp_advertised_groups, bgp_advertised_ip_ranges, self_link, location, project, network
from gcp.gcp_compute_router
where name = '{{ resourceName }}'
10 changes: 10 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-hydrate-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"bgp_advertise_mode": "CUSTOM",
"bgp_asn": 64514,
"description": "Test router to verify the table.",
"kind": "compute#router",
"name": "{{resourceName}}",
"self_link": "{{ output.self_link.value }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-hydrate-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, bgp_asn, description, kind, bgp_advertise_mode, self_link
from gcp.gcp_compute_router
where name = '{{ resourceName }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-invalid-name-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, description
from gcp.gcp_compute_router
where name = ''
6 changes: 6 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-list-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Test router to verify the table.",
"name": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-list-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, description
from gcp.gcp_compute_router
where title = '{{ resourceName }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-not-found-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, kind, description
from gcp.gcp_compute_router
where name = 'dummy-{{ resourceName }}'
8 changes: 8 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-turbot-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"akas": [
"{{ output.resource_aka.value }}"
],
"title": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_compute_router/test-turbot-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select title, akas
from gcp.gcp_compute_router
where name = '{{ resourceName }}'
1 change: 1 addition & 0 deletions gcp-test/tests/gcp_compute_router/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
81 changes: 81 additions & 0 deletions gcp-test/tests/gcp_compute_router/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

variable "resource_name" {
type = string
default = "turbot-test-20200125-create-update"
description = "Name of the resource used throughout the test."
}

variable "gcp_project" {
type = string
default = "niteowl-aaa"
description = "GCP project used for the test."
}

variable "gcp_region" {
type = string
default = "us-east1"
description = "GCP region used for the test."
}

variable "gcp_zone" {
type = string
default = "us-east1-b"
}

provider "google" {
project = var.gcp_project
region = var.gcp_region
zone = var.gcp_zone
}

data "google_client_config" "current" {}

data "null_data_source" "resource" {
inputs = {
scope = "gcp://cloudresourcemanager.googleapis.com/projects/${data.google_client_config.current.project}"
}
}

resource "google_compute_network" "named_test_resource" {
name = var.resource_name
}
resource "google_compute_router" "named_test_resource" {
name = var.resource_name
description = "Test router to verify the table."
network = google_compute_network.named_test_resource.name
bgp {
asn = 64514
advertise_mode = "CUSTOM"
advertised_groups = ["ALL_SUBNETS"]
advertised_ip_ranges {
range = "1.2.3.4"
}
advertised_ip_ranges {
range = "6.7.0.0/16"
}
}
}

output "resource_aka" {
value = "gcp://compute.googleapis.com/${google_compute_router.named_test_resource.id}"
}

output "resource_name" {
value = var.resource_name
}

output "resource_id" {
value = google_compute_router.named_test_resource.id
}

output "self_link" {
value = google_compute_router.named_test_resource.self_link
}

output "network" {
value = google_compute_network.named_test_resource.self_link
}

output "project_id" {
value = var.gcp_project
}
1 change: 1 addition & 0 deletions gcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"gcp_compute_global_forwarding_rule": tableGcpComputeGlobalForwardingRule(ctx),
"gcp_compute_image": tableGcpComputeImage(ctx),
"gcp_compute_instance": tableGcpComputeInstance(ctx),
"gcp_compute_router": tableGcpComputeRouter(ctx),
"gcp_iam_policy": tableGcpIAMPolicy(ctx),
"gcp_iam_role": tableGcpIamRole(ctx),
"gcp_logging_exclusion": tableGcpLoggingExclusion(ctx),
Expand Down
Loading