package google import ( "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 = <