Skip to content

Commit

Permalink
Copy terraform resources and data_sources from magic modules (#556)
Browse files Browse the repository at this point in the history
Merged PR #556.
  • Loading branch information
chrisst authored and modular-magician committed Oct 13, 2018
1 parent 355fbf1 commit 8d2f6ea
Show file tree
Hide file tree
Showing 132 changed files with 34,167 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/terraform
19 changes: 17 additions & 2 deletions provider/terraform/common~copy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@
# the final module tree structure:
<%
dir = _version_name == 'beta' ? 'google-beta' : 'google'
Dir["templates/terraform/tests/*#{api.prefix[1..-1]}*"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
# Handwritten acceptance tests for autogenerated resources.
# Adding them here allows updating the tests as part of a MM pull request.
<% Dir["templates/terraform/tests/*#{api.prefix[1..-1]}*"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/<%= fname -%>': 'templates/terraform/tests/<%= fname -%>'
<% end -%>
# Copy all of the terraform resources that are still hand written
<%
Dir["provider/terraform/resources/*#{api.prefix[1..-1]}*"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/<%= fname -%>': 'provider/terraform/resources/<%= fname -%>'
<% end -%>
<%
Dir["provider/terraform/data_sources/*#{api.prefix[1..-1]}*"].each do |file_path|
fname = file_path.split('/')[-1]
-%>
'<%= dir -%>/<%= fname -%>': 'provider/terraform/data_sources/<%= fname -%>'
<% end -%>

'<%= dir -%>/transport.go': 'templates/terraform/transport.go'
'<%= dir -%>/transport_test.go': 'templates/terraform/transport_test.go'
'<%= dir -%>/import.go': 'templates/terraform/import.go'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package google

import (
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleComputeLbIpRanges() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleComputeLbIpRangesRead,

Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"http_ssl_tcp_internal": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
},
}
}

func dataSourceGoogleComputeLbIpRangesRead(d *schema.ResourceData, meta interface{}) error {
d.SetId("compute-lb-ip-ranges")

// https://cloud.google.com/compute/docs/load-balancing/health-checks#health_check_source_ips_and_firewall_rules

networkIpRanges := []string{
"209.85.152.0/22",
"209.85.204.0/22",
"35.191.0.0/16",
}
d.Set("network", networkIpRanges)

httpSslTcpInternalRanges := []string{
"130.211.0.0/22",
"35.191.0.0/16",
}
d.Set("http_ssl_tcp_internal", httpSslTcpInternalRanges)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleContainerImage() *schema.Resource {
return &schema.Resource{
Read: containerRegistryImageRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"tag": {
Type: schema.TypeString,
Optional: true,
},
"digest": {
Type: schema.TypeString,
Optional: true,
},
"region": {
Type: schema.TypeString,
Optional: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"image_url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func containerRegistryImageRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
d.Set("project", project)
region, ok := d.GetOk("region")
var url_base string
if ok && region != nil && region != "" {
url_base = fmt.Sprintf("%s.gcr.io/%s", region, project)
} else {
url_base = fmt.Sprintf("gcr.io/%s", project)
}
tag, t_ok := d.GetOk("tag")
digest, d_ok := d.GetOk("digest")
if t_ok && tag != nil && tag != "" {
d.Set("image_url", fmt.Sprintf("%s/%s:%s", url_base, d.Get("name").(string), tag))
} else if d_ok && digest != nil && digest != "" {
d.Set("image_url", fmt.Sprintf("%s/%s@%s", url_base, d.Get("name").(string), digest))
} else {
d.Set("image_url", fmt.Sprintf("%s/%s", url_base, d.Get("name").(string)))
}
d.SetId(d.Get("image_url").(string))
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleContainerRepo() *schema.Resource {
return &schema.Resource{
Read: containerRegistryRepoRead,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"repository_url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func containerRegistryRepoRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
d.Set("project", project)
region, ok := d.GetOk("region")
if ok && region != nil && region != "" {
d.Set("repository_url", fmt.Sprintf("%s.gcr.io/%s", region, project))
} else {
d.Set("repository_url", fmt.Sprintf("gcr.io/%s", project))
}
d.SetId(d.Get("repository_url").(string))
return nil
}
65 changes: 65 additions & 0 deletions provider/terraform/data_sources/data_source_dns_managed_zone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package google

import "github.com/hashicorp/terraform/helper/schema"

func dataSourceDnsManagedZone() *schema.Resource {
return &schema.Resource{
Read: dataSourceDnsManagedZoneRead,

Schema: map[string]*schema.Schema{
"dns_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},

"description": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"name_servers": &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

// Google Cloud DNS ManagedZone resources do not have a SelfLink attribute.

"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}

func dataSourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

d.SetId(d.Get("name").(string))

project, err := getProject(d, config)
if err != nil {
return err
}

zone, err := config.clientDns.ManagedZones.Get(
project, d.Id()).Do()
if err != nil {
return err
}

d.Set("name_servers", zone.NameServers)
d.Set("name", zone.Name)
d.Set("dns_name", zone.DnsName)
d.Set("description", zone.Description)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package google

import (
"fmt"
"net/url"

"github.com/hashicorp/terraform/helper/schema"
resourceManagerV2Beta1 "google.golang.org/api/cloudresourcemanager/v2beta1"
)

func dataSourceGoogleActiveFolder() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleActiveFolderRead,

Schema: map[string]*schema.Schema{
"parent": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"display_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceGoogleActiveFolderRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

parent := d.Get("parent").(string)
displayName := d.Get("display_name").(string)

queryString := fmt.Sprintf("lifecycleState=ACTIVE AND parent=%s AND displayName=%s", parent, url.QueryEscape(displayName))
searchRequest := &resourceManagerV2Beta1.SearchFoldersRequest{
Query: queryString,
}
searchResponse, err := config.clientResourceManagerV2Beta1.Folders.Search(searchRequest).Do()
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Folder Not Found : %s", displayName))
}

for _, folder := range searchResponse.Folders {
if folder.DisplayName == displayName {
d.SetId(folder.Name)
d.Set("name", folder.Name)
return nil
}
}
return fmt.Errorf("Folder not found")
}
Loading

0 comments on commit 8d2f6ea

Please sign in to comment.