mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-01 07:42:40 +00:00
Remove beta generated resource maps from GA provider. (#2350)
<!-- This change is generated by MagicModules. --> /cc @rileykarson
This commit is contained in:
parent
35d6d71cd7
commit
5a47db4d94
|
@ -1,71 +1,3 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
|
||||||
file "google.golang.org/api/file/v1beta1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FilestoreOperationWaiter struct {
|
|
||||||
Service *file.ProjectsLocationsService
|
|
||||||
Op *file.Operation
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *FilestoreOperationWaiter) RefreshFunc() resource.StateRefreshFunc {
|
|
||||||
return func() (interface{}, string, error) {
|
|
||||||
op, err := w.Service.Operations.Get(w.Op.Name).Do()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[DEBUG] Got %v while polling for operation %s's 'done' status", op.Done, w.Op.Name)
|
|
||||||
|
|
||||||
return op, fmt.Sprint(op.Done), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *FilestoreOperationWaiter) Conf() *resource.StateChangeConf {
|
|
||||||
return &resource.StateChangeConf{
|
|
||||||
Pending: []string{"false"},
|
|
||||||
Target: []string{"true"},
|
|
||||||
Refresh: w.RefreshFunc(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func filestoreOperationWait(service *file.Service, op *file.Operation, project, activity string) error {
|
|
||||||
return filestoreOperationWaitTime(service, op, project, activity, 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
func filestoreOperationWaitTime(service *file.Service, op *file.Operation, project, activity string, timeoutMin int) error {
|
|
||||||
if op.Done {
|
|
||||||
if op.Error != nil {
|
|
||||||
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
w := &FilestoreOperationWaiter{
|
|
||||||
Service: service.Projects.Locations,
|
|
||||||
Op: op,
|
|
||||||
}
|
|
||||||
|
|
||||||
state := w.Conf()
|
|
||||||
state.Delay = 10 * time.Second
|
|
||||||
state.Timeout = time.Duration(timeoutMin) * time.Minute
|
|
||||||
state.MinTimeout = 2 * time.Second
|
|
||||||
opRaw, err := state.WaitForState()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error waiting for %s: %s", activity, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
op = opRaw.(*file.Operation)
|
|
||||||
if op.Error != nil {
|
|
||||||
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,182 +1,3 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationAttestor_basic(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationAttestorBasic(name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_attestor.attestor",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationAttestor_full(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationAttestorFull(name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_attestor.attestor",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationAttestor_update(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccBinaryAuthorizationAttestorBasic(name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_attestor.attestor",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationAttestorFull(name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_attestor.attestor",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationAttestorBasic(name),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_attestor.attestor",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckBinaryAuthorizationAttestorDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_binary_authorization_attestor" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
project, err := getTestProject(rs.Primary, config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
name := rs.Primary.Attributes["name"]
|
|
||||||
|
|
||||||
url := fmt.Sprintf("https://binaryauthorization.googleapis.com/v1beta1/projects/%s/attestors/%s", project, name)
|
|
||||||
_, err = sendRequest(config, "GET", url, nil)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Error, attestor %s still exists", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccBinaryAuthorizationAttestorBasic(name string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_container_analysis_note" "note" {
|
|
||||||
name = "tf-test-%s"
|
|
||||||
attestation_authority {
|
|
||||||
hint {
|
|
||||||
human_readable_name = "My Attestor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_binary_authorization_attestor" "attestor" {
|
|
||||||
name = "tf-test-%s"
|
|
||||||
attestation_authority_note {
|
|
||||||
note_reference = "${google_container_analysis_note.note.name}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, name, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccBinaryAuthorizationAttestorFull(name string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_container_analysis_note" "note" {
|
|
||||||
name = "tf-test-%s"
|
|
||||||
attestation_authority {
|
|
||||||
hint {
|
|
||||||
human_readable_name = "My Attestor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_binary_authorization_attestor" "attestor" {
|
|
||||||
name = "tf-test-%s"
|
|
||||||
description = "my description"
|
|
||||||
attestation_authority_note {
|
|
||||||
note_reference = "${google_container_analysis_note.note.name}"
|
|
||||||
public_keys {
|
|
||||||
ascii_armored_pgp_public_key = <<EOF
|
|
||||||
%s
|
|
||||||
EOF
|
|
||||||
comment = "this key has a comment"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, name, name, armoredPubKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generated key using instructions from
|
|
||||||
// https://cloud.google.com/binary-authorization/docs/creating-attestors#generate_pgp_key_pairs.
|
|
||||||
// This key has no real meaning and was generated in order to have a valid key
|
|
||||||
// for testing.
|
|
||||||
const armoredPubKey = `mQENBFtP0doBCADF+joTiXWKVuP8kJt3fgpBSjT9h8ezMfKA4aXZctYLx5wslWQl
|
|
||||||
bB7Iu2ezkECNzoEeU7WxUe8a61pMCh9cisS9H5mB2K2uM4Jnf8tgFeXn3akJDVo0
|
|
||||||
oR1IC+Dp9mXbRSK3MAvKkOwWlG99sx3uEdvmeBRHBOO+grchLx24EThXFOyP9Fk6
|
|
||||||
V39j6xMjw4aggLD15B4V0v9JqBDdJiIYFzszZDL6pJwZrzcP0z8JO4rTZd+f64bD
|
|
||||||
Mpj52j/pQfA8lZHOaAgb1OrthLdMrBAjoDjArV4Ek7vSbrcgYWcI6BhsQrFoxKdX
|
|
||||||
83TZKai55ZCfCLIskwUIzA1NLVwyzCS+fSN/ABEBAAG0KCJUZXN0IEF0dGVzdG9y
|
|
||||||
IiA8ZGFuYWhvZmZtYW5AZ29vZ2xlLmNvbT6JAU4EEwEIADgWIQRfWkqHt6hpTA1L
|
|
||||||
uY060eeM4dc66AUCW0/R2gIbLwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRA6
|
|
||||||
0eeM4dc66HdpCAC4ot3b0OyxPb0Ip+WT2U0PbpTBPJklesuwpIrM4Lh0N+1nVRLC
|
|
||||||
51WSmVbM8BiAFhLbN9LpdHhds1kUrHF7+wWAjdR8sqAj9otc6HGRM/3qfa2qgh+U
|
|
||||||
WTEk/3us/rYSi7T7TkMuutRMIa1IkR13uKiW56csEMnbOQpn9rDqwIr5R8nlZP5h
|
|
||||||
MAU9vdm1DIv567meMqTaVZgR3w7bck2P49AO8lO5ERFpVkErtu/98y+rUy9d789l
|
|
||||||
+OPuS1NGnxI1YKsNaWJF4uJVuvQuZ1twrhCbGNtVorO2U12+cEq+YtUxj7kmdOC1
|
|
||||||
qoIRW6y0+UlAc+MbqfL0ziHDOAmcqz1GnROg
|
|
||||||
=6Bvm`
|
|
||||||
|
|
|
@ -1,226 +1,3 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationPolicy_basic(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
org := getTestOrgFromEnv(t)
|
|
||||||
pid := "tf-test-" + acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_policy.policy",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
// Destroy the policy without destroying the project so we can check
|
|
||||||
// that it was restored to the default.
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org),
|
|
||||||
Check: testAccCheckBinaryAuthorizationPolicyDefault(pid),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationPolicy_full(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
org := getTestOrgFromEnv(t)
|
|
||||||
pid := "tf-test-" + acctest.RandString(10)
|
|
||||||
note := acctest.RandString(10)
|
|
||||||
attestor := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_policy.policy",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
// Destroy the policy without destroying the project so we can check
|
|
||||||
// that it was restored to the default.
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org),
|
|
||||||
Check: testAccCheckBinaryAuthorizationPolicyDefault(pid),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccBinaryAuthorizationPolicy_update(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
org := getTestOrgFromEnv(t)
|
|
||||||
pid := "tf-test-" + acctest.RandString(10)
|
|
||||||
note := acctest.RandString(10)
|
|
||||||
attestor := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_policy.policy",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_policy.policy",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_binary_authorization_policy.policy",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
// Destroy the policy without destroying the project so we can check
|
|
||||||
// that it was restored to the default.
|
|
||||||
{
|
|
||||||
Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org),
|
|
||||||
Check: testAccCheckBinaryAuthorizationPolicyDefault(pid),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckBinaryAuthorizationPolicyDefault(pid string) resource.TestCheckFunc {
|
|
||||||
return func(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
url := fmt.Sprintf("https://binaryauthorization.googleapis.com/v1beta1/projects/%s/policy", pid)
|
|
||||||
pol, err := sendRequest(config, "GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
delete(pol, "updateTime")
|
|
||||||
|
|
||||||
defaultPol := defaultBinaryAuthorizationPolicy(pid)
|
|
||||||
if !reflect.DeepEqual(pol, defaultPol) {
|
|
||||||
return fmt.Errorf("Policy for project %s was %v, expected default policy %v", pid, pol, defaultPol)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccBinaryAuthorizationPolicyDefault(pid, pname, org string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
// Use a separate project since each project can only have one policy
|
|
||||||
resource "google_project" "project" {
|
|
||||||
project_id = "%s"
|
|
||||||
name = "%s"
|
|
||||||
org_id = "%s"
|
|
||||||
}
|
|
||||||
`, pid, pname, org)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccBinaryAuthorizationPolicyBasic(pid, pname, org string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
// Use a separate project since each project can only have one policy
|
|
||||||
resource "google_project" "project" {
|
|
||||||
project_id = "%s"
|
|
||||||
name = "%s"
|
|
||||||
org_id = "%s"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_binary_authorization_policy" "policy" {
|
|
||||||
project = "${google_project.project.project_id}"
|
|
||||||
|
|
||||||
admission_whitelist_patterns {
|
|
||||||
name_pattern= "gcr.io/google_containers/*"
|
|
||||||
}
|
|
||||||
|
|
||||||
default_admission_rule {
|
|
||||||
evaluation_mode = "ALWAYS_DENY"
|
|
||||||
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, pid, pname, org)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
// Use a separate project since each project can only have one policy
|
|
||||||
resource "google_project" "project" {
|
|
||||||
project_id = "%s"
|
|
||||||
name = "%s"
|
|
||||||
org_id = "%s"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_project_service" "binauthz" {
|
|
||||||
project = "${google_project.project.project_id}"
|
|
||||||
service = "binaryauthorization.googleapis.com"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_container_analysis_note" "note" {
|
|
||||||
project = "${google_project.project.project_id}"
|
|
||||||
|
|
||||||
name = "tf-test-%s"
|
|
||||||
attestation_authority {
|
|
||||||
hint {
|
|
||||||
human_readable_name = "My attestor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
depends_on = ["google_project_service.binauthz"]
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_binary_authorization_attestor" "attestor" {
|
|
||||||
project = "${google_project.project.project_id}"
|
|
||||||
|
|
||||||
name = "tf-test-%s"
|
|
||||||
description = "my description"
|
|
||||||
attestation_authority_note {
|
|
||||||
note_reference = "${google_container_analysis_note.note.name}"
|
|
||||||
}
|
|
||||||
|
|
||||||
depends_on = ["google_project_service.binauthz"]
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "google_binary_authorization_policy" "policy" {
|
|
||||||
project = "${google_project.project.project_id}"
|
|
||||||
|
|
||||||
admission_whitelist_patterns {
|
|
||||||
name_pattern= "gcr.io/google_containers/*"
|
|
||||||
}
|
|
||||||
|
|
||||||
default_admission_rule {
|
|
||||||
evaluation_mode = "ALWAYS_ALLOW"
|
|
||||||
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
|
|
||||||
}
|
|
||||||
|
|
||||||
cluster_admission_rules {
|
|
||||||
cluster = "us-central1-a.prod-cluster"
|
|
||||||
evaluation_mode = "REQUIRE_ATTESTATION"
|
|
||||||
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
|
|
||||||
require_attestations_by = ["${google_binary_authorization_attestor.attestor.name}"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, pid, pname, org, note, attestor)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,102 +1,3 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccContainerAnalysisNote_basic(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandString(10)
|
|
||||||
readableName := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckContainerAnalysisNoteDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccContainerAnalysisNoteBasic(name, readableName),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_container_analysis_note.note",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccContainerAnalysisNote_update(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandString(10)
|
|
||||||
readableName := acctest.RandString(10)
|
|
||||||
readableName2 := acctest.RandString(10)
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckContainerAnalysisNoteDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
{
|
|
||||||
Config: testAccContainerAnalysisNoteBasic(name, readableName),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_container_analysis_note.note",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Config: testAccContainerAnalysisNoteBasic(name, readableName2),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ResourceName: "google_container_analysis_note.note",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckContainerAnalysisNoteDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_container_analysis_note" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
project, err := getTestProject(rs.Primary, config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
name := rs.Primary.Attributes["name"]
|
|
||||||
|
|
||||||
url := fmt.Sprintf("https://containeranalysis.googleapis.com/v1alpha1/projects/%s/notes/%s", project, name)
|
|
||||||
_, err = sendRequest(config, "GET", url, nil)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Error, container analysis note %s still exists", name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccContainerAnalysisNoteBasic(name, readableName string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_container_analysis_note" "note" {
|
|
||||||
name = "tf-test-%s"
|
|
||||||
attestation_authority {
|
|
||||||
hint {
|
|
||||||
human_readable_name = "My Attestor %s"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`, name, readableName)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,149 +1,3 @@
|
||||||
package google
|
package google
|
||||||
|
|
||||||
import (
|
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/acctest"
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestAccFilestoreInstance_basic(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandomWithPrefix("tf-test")
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckFilestoreInstanceDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccFilestoreInstance_basic(name),
|
|
||||||
},
|
|
||||||
resource.TestStep{
|
|
||||||
ResourceName: "google_filestore_instance.instance",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAccFilestoreInstance_update(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
name := acctest.RandomWithPrefix("tf-test")
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckFilestoreInstanceDestroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccFilestoreInstance_update(name),
|
|
||||||
},
|
|
||||||
resource.TestStep{
|
|
||||||
ResourceName: "google_filestore_instance.instance",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testAccFilestoreInstance_update2(name),
|
|
||||||
},
|
|
||||||
resource.TestStep{
|
|
||||||
ResourceName: "google_filestore_instance.instance",
|
|
||||||
ImportState: true,
|
|
||||||
ImportStateVerify: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccCheckFilestoreInstanceDestroy(s *terraform.State) error {
|
|
||||||
config := testAccProvider.Meta().(*Config)
|
|
||||||
|
|
||||||
for _, rs := range s.RootModule().Resources {
|
|
||||||
if rs.Type != "google_filestore_instance" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
redisIdParts := strings.Split(rs.Primary.ID, "/")
|
|
||||||
if len(redisIdParts) != 3 {
|
|
||||||
return fmt.Errorf("Unexpected resource ID %s, expected {project}/{region}/{name}", rs.Primary.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
project, region, inst := redisIdParts[0], redisIdParts[1], redisIdParts[2]
|
|
||||||
|
|
||||||
name := fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, inst)
|
|
||||||
_, err := config.clientFilestore.Projects.Locations.Get(name).Do()
|
|
||||||
if err == nil {
|
|
||||||
return fmt.Errorf("Filestore instance still exists")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccFilestoreInstance_basic(name string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_filestore_instance" "instance" {
|
|
||||||
name = "tf-instance-%s"
|
|
||||||
zone = "us-central1-b"
|
|
||||||
file_shares {
|
|
||||||
capacity_gb = 2560
|
|
||||||
name = "share"
|
|
||||||
}
|
|
||||||
networks {
|
|
||||||
network = "default"
|
|
||||||
modes = ["MODE_IPV4"]
|
|
||||||
}
|
|
||||||
labels {
|
|
||||||
foo = "bar"
|
|
||||||
}
|
|
||||||
tier = "PREMIUM"
|
|
||||||
}
|
|
||||||
`, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccFilestoreInstance_update(name string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_filestore_instance" "instance" {
|
|
||||||
name = "tf-instance-%s"
|
|
||||||
zone = "us-central1-b"
|
|
||||||
file_shares {
|
|
||||||
capacity_gb = 2660
|
|
||||||
name = "share"
|
|
||||||
}
|
|
||||||
networks {
|
|
||||||
network = "default"
|
|
||||||
modes = ["MODE_IPV4"]
|
|
||||||
}
|
|
||||||
labels {
|
|
||||||
baz = "qux"
|
|
||||||
}
|
|
||||||
tier = "PREMIUM"
|
|
||||||
description = "An instance created during testing."
|
|
||||||
}
|
|
||||||
`, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAccFilestoreInstance_update2(name string) string {
|
|
||||||
return fmt.Sprintf(`
|
|
||||||
resource "google_filestore_instance" "instance" {
|
|
||||||
name = "tf-instance-%s"
|
|
||||||
zone = "us-central1-b"
|
|
||||||
file_shares {
|
|
||||||
capacity_gb = 2760
|
|
||||||
name = "share"
|
|
||||||
}
|
|
||||||
networks {
|
|
||||||
network = "default"
|
|
||||||
modes = ["MODE_IPV4"]
|
|
||||||
}
|
|
||||||
tier = "PREMIUM"
|
|
||||||
description = "A modified instance created during testing."
|
|
||||||
}`, name)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user