-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add global forwarding rule datasource * fix broken test * fix typos Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
795e744
commit 5d93cfb
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-datasource | ||
compute: added `google_compute_global_forwarding_rule` datasource | ||
``` |
37 changes: 37 additions & 0 deletions
37
google/data_source_google_global_compute_forwarding_rule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeGlobalForwardingRule() *schema.Resource { | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeGlobalForwardingRule().Schema) | ||
|
||
// Set 'Required' schema elements | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
|
||
// Set 'Optional' schema elements | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleComputeGlobalForwardingRuleRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
name := d.Get("name").(string) | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(fmt.Sprintf("projects/%s/global/forwardingRules/%s", project, name)) | ||
|
||
return resourceComputeGlobalForwardingRuleRead(d, meta) | ||
} |
55 changes: 55 additions & 0 deletions
55
google/data_source_google_global_compute_forwarding_rule_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleGlobalForwardingRule(t *testing.T) { | ||
t.Parallel() | ||
|
||
poolName := fmt.Sprintf("tf-%s", randString(t, 10)) | ||
ruleName := fmt.Sprintf("tf-%s", randString(t, 10)) | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleGlobalForwardingRuleConfig(poolName, ruleName), | ||
Check: checkDataSourceStateMatchesResourceState("data.google_compute_global_forwarding_rule.my_forwarding_rule", "google_compute_global_forwarding_rule.foobar-fr"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleGlobalForwardingRuleConfig(poolName, ruleName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_global_forwarding_rule" "foobar-fr" { | ||
name = "%s" | ||
target = google_compute_target_http_proxy.default.id | ||
port_range = "80" | ||
} | ||
resource "google_compute_target_http_proxy" "default" { | ||
name = "%s" | ||
description = "a description" | ||
url_map = google_compute_url_map.default.id | ||
} | ||
resource "google_compute_url_map" "default" { | ||
name = "%s" | ||
default_url_redirect { | ||
https_redirect = true | ||
redirect_response_code = "MOVED_PERMANENTLY_DEFAULT" | ||
strip_query = false | ||
} | ||
} | ||
data "google_compute_global_forwarding_rule" "my_forwarding_rule" { | ||
name = google_compute_global_forwarding_rule.foobar-fr.name | ||
} | ||
`, ruleName, poolName, poolName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
website/docs/d/compute_global_forwarding_rule.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
subcategory: "Compute Engine" | ||
layout: "google" | ||
page_title: "Google: google_compute_global_forwarding_rule" | ||
sidebar_current: "docs-google-datasource-compute-global_forwarding-rule" | ||
description: |- | ||
Get a global forwarding rule within GCE. | ||
--- | ||
|
||
# google\_compute\_global_\forwarding\_rule | ||
|
||
Get a global forwarding rule within GCE from its name. | ||
|
||
## Example Usage | ||
|
||
```tf | ||
data "google_compute_global_forwarding_rule" "my-forwarding-rule" { | ||
name = "forwarding-rule-global" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the global forwarding rule. | ||
|
||
- - - | ||
|
||
* `project` - (Optional) The project in which the resource belongs. If it | ||
is not provided, the provider project is used. | ||
|
||
## Attributes Reference | ||
See [google_compute_global_forwarding_rule](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html) resource for details of the available attributes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters