|
| 1 | +package google |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform/helper/schema" |
| 7 | +) |
| 8 | + |
| 9 | +func dataSourceGoogleComputeForwardingRule() *schema.Resource { |
| 10 | + return &schema.Resource{ |
| 11 | + Read: dataSourceGoogleComputeForwardingRuleRead, |
| 12 | + |
| 13 | + Schema: map[string]*schema.Schema{ |
| 14 | + "name": &schema.Schema{ |
| 15 | + Type: schema.TypeString, |
| 16 | + Required: true, |
| 17 | + }, |
| 18 | + |
| 19 | + "region": &schema.Schema{ |
| 20 | + Type: schema.TypeString, |
| 21 | + Optional: true, |
| 22 | + Computed: true, |
| 23 | + }, |
| 24 | + |
| 25 | + "project": &schema.Schema{ |
| 26 | + Type: schema.TypeString, |
| 27 | + Optional: true, |
| 28 | + Computed: true, |
| 29 | + }, |
| 30 | + |
| 31 | + "target": &schema.Schema{ |
| 32 | + Type: schema.TypeString, |
| 33 | + Computed: true, |
| 34 | + }, |
| 35 | + |
| 36 | + "backend_service": &schema.Schema{ |
| 37 | + Type: schema.TypeString, |
| 38 | + Computed: true, |
| 39 | + }, |
| 40 | + |
| 41 | + "description": &schema.Schema{ |
| 42 | + Type: schema.TypeString, |
| 43 | + Computed: true, |
| 44 | + }, |
| 45 | + |
| 46 | + "ip_address": &schema.Schema{ |
| 47 | + Type: schema.TypeString, |
| 48 | + Computed: true, |
| 49 | + }, |
| 50 | + |
| 51 | + "ip_protocol": &schema.Schema{ |
| 52 | + Type: schema.TypeString, |
| 53 | + Computed: true, |
| 54 | + }, |
| 55 | + |
| 56 | + "load_balancing_scheme": &schema.Schema{ |
| 57 | + Type: schema.TypeString, |
| 58 | + Computed: true, |
| 59 | + }, |
| 60 | + |
| 61 | + "network": &schema.Schema{ |
| 62 | + Type: schema.TypeString, |
| 63 | + Computed: true, |
| 64 | + }, |
| 65 | + |
| 66 | + "port_range": &schema.Schema{ |
| 67 | + Type: schema.TypeString, |
| 68 | + Computed: true, |
| 69 | + }, |
| 70 | + |
| 71 | + "ports": &schema.Schema{ |
| 72 | + Type: schema.TypeSet, |
| 73 | + Elem: &schema.Schema{Type: schema.TypeString}, |
| 74 | + Computed: true, |
| 75 | + }, |
| 76 | + |
| 77 | + "self_link": &schema.Schema{ |
| 78 | + Type: schema.TypeString, |
| 79 | + Computed: true, |
| 80 | + }, |
| 81 | + |
| 82 | + "subnetwork": &schema.Schema{ |
| 83 | + Type: schema.TypeString, |
| 84 | + Computed: true, |
| 85 | + }, |
| 86 | + }, |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func dataSourceGoogleComputeForwardingRuleRead(d *schema.ResourceData, meta interface{}) error { |
| 91 | + config := meta.(*Config) |
| 92 | + |
| 93 | + region, err := getRegion(d, config) |
| 94 | + if err != nil { |
| 95 | + return err |
| 96 | + } |
| 97 | + |
| 98 | + project, err := getProject(d, config) |
| 99 | + if err != nil { |
| 100 | + return err |
| 101 | + } |
| 102 | + |
| 103 | + name := d.Get("name").(string) |
| 104 | + |
| 105 | + frule, err := config.clientCompute.ForwardingRules.Get( |
| 106 | + project, region, name).Do() |
| 107 | + if err != nil { |
| 108 | + return handleNotFoundError(err, d, fmt.Sprintf("Forwarding Rule Not Found : %s", name)) |
| 109 | + } |
| 110 | + d.SetId(frule.Name) |
| 111 | + |
| 112 | + d.Set("self_link", frule.SelfLink) |
| 113 | + d.Set("description", frule.Description) |
| 114 | + d.Set("backend_service", frule.BackendService) |
| 115 | + d.Set("ip_address", frule.IPAddress) |
| 116 | + d.Set("ip_protocol", frule.IPProtocol) |
| 117 | + d.Set("load_balancing_scheme", frule.LoadBalancingScheme) |
| 118 | + d.Set("name", frule.Name) |
| 119 | + d.Set("port_range", frule.PortRange) |
| 120 | + d.Set("ports", frule.Ports) |
| 121 | + d.Set("subnetwork", frule.Subnetwork) |
| 122 | + d.Set("network", frule.Network) |
| 123 | + d.Set("target", frule.Target) |
| 124 | + d.Set("project", project) |
| 125 | + d.Set("region", region) |
| 126 | + |
| 127 | + return nil |
| 128 | +} |
0 commit comments