-
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.
Merge branch 'master' into gke-regional-clusters-support
- Loading branch information
Showing
112 changed files
with
2,874 additions
and
1,196 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
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
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,28 @@ | ||
package google | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeBackendService() *schema.Resource { | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeBackendService().Schema) | ||
|
||
// Set 'Required' schema elements | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
|
||
// Set 'Optional' schema elements | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceComputeBackendServiceRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceComputeBackendServiceRead(d *schema.ResourceData, meta interface{}) error { | ||
serviceName := d.Get("name").(string) | ||
|
||
d.SetId(serviceName) | ||
|
||
return resourceComputeBackendServiceRead(d, meta) | ||
} |
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,85 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDataSourceComputeBackendService_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckComputeBackendServiceDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDataSourceComputeBackendService_basic(serviceName, checkName), | ||
Check: testAccDataSourceComputeBackendServiceCheck("data.google_compute_backend_service.baz", "google_compute_backend_service.foobar"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceComputeBackendServiceCheck(dsName, rsName string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[rsName] | ||
if !ok { | ||
return fmt.Errorf("can't find resource called %s in state", rsName) | ||
} | ||
|
||
ds, ok := s.RootModule().Resources[dsName] | ||
if !ok { | ||
return fmt.Errorf("can't find data source called %s in state", dsName) | ||
} | ||
|
||
dsAttr := ds.Primary.Attributes | ||
rsAttr := rs.Primary.Attributes | ||
|
||
attrsToTest := []string{ | ||
"id", | ||
"name", | ||
"description", | ||
"self_link", | ||
"fingerprint", | ||
"port_name", | ||
"protocol", | ||
} | ||
|
||
for _, attrToTest := range attrsToTest { | ||
if dsAttr[attrToTest] != rsAttr[attrToTest] { | ||
return fmt.Errorf("%s is %s; want %s", attrToTest, dsAttr[attrToTest], rsAttr[attrToTest]) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccDataSourceComputeBackendService_basic(serviceName, checkName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_backend_service" "foobar" { | ||
name = "%s" | ||
description = "foobar backend service" | ||
health_checks = ["${google_compute_http_health_check.zero.self_link}"] | ||
} | ||
resource "google_compute_http_health_check" "zero" { | ||
name = "%s" | ||
request_path = "/" | ||
check_interval_sec = 1 | ||
timeout_sec = 1 | ||
} | ||
data "google_compute_backend_service" "baz" { | ||
name = "${google_compute_backend_service.foobar.name}" | ||
} | ||
`, serviceName, checkName) | ||
} |
40 changes: 40 additions & 0 deletions
40
google/data_source_google_compute_default_service_account.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,40 @@ | ||
package google | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeDefaultServiceAccount() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGoogleComputeDefaultServiceAccountRead, | ||
Schema: map[string]*schema.Schema{ | ||
"email": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"project": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGoogleComputeDefaultServiceAccountRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectCompResource, err := config.clientCompute.Projects.Get(project).Do() | ||
if err != nil { | ||
return handleNotFoundError(err, d, "GCE service account not found") | ||
} | ||
|
||
d.SetId(projectCompResource.DefaultServiceAccount) | ||
d.Set("email", projectCompResource.DefaultServiceAccount) | ||
d.Set("project", project) | ||
return nil | ||
} |
31 changes: 31 additions & 0 deletions
31
google/data_source_google_compute_default_service_account_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,31 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleComputeDefaultServiceAccount_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
resourceName := "data.google_compute_default_service_account.default" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckGoogleComputeDefaultServiceAccount_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(resourceName, "id"), | ||
resource.TestCheckResourceAttrSet(resourceName, "email"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckGoogleComputeDefaultServiceAccount_basic = ` | ||
data "google_compute_default_service_account" "default" { } | ||
` |
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
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
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
Oops, something went wrong.