Skip to content

Commit

Permalink
Add table gcp_dns_managed_zone. Closes #143 (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Subhajit97 committed Mar 30, 2021
1 parent 1dede68 commit d405b65
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/tables/gcp_dns_managed_zone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Table: gcp_dns_managed_zone

A DNS zone is used to host the DNS records for a particular domain. To start hosting your domain in Azure DNS, you need to create a DNS zone for that domain name. Each DNS record for your domain is then created inside this DNS zone.

## Examples

### Basic info

```sql
select
name,
id,
dns_name,
creation_time,
visibility
from
gcp_dns_managed_zone;
```

### List public zones with DNSSEC disabled

```sql
select
name,
id,
dns_name,
dnssec_config_state,
visibility
from
gcp_dns_managed_zone
where
visibility = 'public'
and dnssec_config_state <> 'on';
```
Empty file.
21 changes: 21 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"description": "Test managed zone to validate the table outcome.",
"dns_name": "turbot.com.",
"kind": "dns#managedZone",
"labels": {
"name": "{{ resourceName }}"
},
"location": "global",
"name": "{{ resourceName }}",
"name_servers": ["ns-gcp-private.googledomains.com."],
"private_visibility_config_networks": [
{
"kind": "dns#managedZonePrivateVisibilityConfigNetwork",
"networkUrl": "{{ output.network.value }}"
}
],
"project": "{{ output.project_id.value }}",
"visibility": "private"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-get-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, dns_name, description, kind, visibility, private_visibility_config_networks, labels, name_servers, location, project
from gcp.gcp_dns_managed_zone
where name = '{{ resourceName }}';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, id, description
from gcp.gcp_dns_managed_zone
where name = '';
6 changes: 6 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-list-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "Test managed zone to validate the table outcome.",
"name": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-list-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select name, description
from gcp.gcp_dns_managed_zone
where akas::text = '["{{ output.resource_aka.value }}"]';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/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_dns_managed_zone
where name = 'dummy-{{ resourceName }}'
9 changes: 9 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-turbot-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"akas": ["{{ output.resource_aka.value }}"],
"tags": {
"name": "{{ resourceName }}"
},
"title": "{{ resourceName }}"
}
]
3 changes: 3 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/test-turbot-query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select title, tags, akas
from gcp.gcp_dns_managed_zone
where name = '{{ resourceName }}';
1 change: 1 addition & 0 deletions gcp-test/tests/gcp_dns_managed_zone/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
79 changes: 79 additions & 0 deletions gcp-test/tests/gcp_dns_managed_zone/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

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_dns_managed_zone" "named_test_resource" {
name = var.resource_name
dns_name = "turbot.com."
description = "Test managed zone to validate the table outcome."
labels = {
name = var.resource_name
}

visibility = "private"

private_visibility_config {
networks {
network_url = google_compute_network.named_test_resource.id
}
}
}

resource "google_compute_network" "named_test_resource" {
name = var.resource_name
auto_create_subnetworks = false
}

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

output "resource_name" {
value = var.resource_name
}

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

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 @@ -56,6 +56,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"gcp_compute_url_map": tableGcpComputeURLMap(ctx),
"gcp_compute_vpn_tunnel": tableGcpComputeVpnTunnel(ctx),
"gcp_compute_zone": tableGcpComputeZone(ctx),
"gcp_dns_managed_zone": tableGcpDnsManagedZone(ctx),
"gcp_iam_policy": tableGcpIAMPolicy(ctx),
"gcp_iam_role": tableGcpIamRole(ctx),
"gcp_logging_exclusion": tableGcpLoggingExclusion(ctx),
Expand Down
22 changes: 22 additions & 0 deletions gcp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"google.golang.org/api/cloudfunctions/v1"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/compute/v1"
"google.golang.org/api/dns/v1"
"google.golang.org/api/iam/v1"
"google.golang.org/api/logging/v2"
"google.golang.org/api/monitoring/v3"
Expand Down Expand Up @@ -167,6 +168,27 @@ func CloudFunctionsService(ctx context.Context, d *plugin.QueryData) (*cloudfunc
return svc, nil
}

// DnsService returns the service connection for GCP DNS service
func DnsService(ctx context.Context, d *plugin.QueryData) (*dns.Service, error) {
// have we already created and cached the service?
serviceCacheKey := "DnsService"
if cachedData, ok := d.ConnectionManager.Cache.Get(serviceCacheKey); ok {
return cachedData.(*dns.Service), nil
}

// To get config arguments from plugin config file
setSessionConfig(d.Connection)

// so it was not in cache - create service
svc, err := dns.NewService(ctx)
if err != nil {
return nil, err
}

d.ConnectionManager.Cache.Set(serviceCacheKey, svc)
return svc, nil
}

// IAMService returns the service connection for GCP IAM service
func IAMService(ctx context.Context, d *plugin.QueryData) (*iam.Service, error) {
// have we already created and cached the service?
Expand Down
Loading

0 comments on commit d405b65

Please sign in to comment.