-
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.
Add example, fix inferred zone for disk resource policies attachment
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
cf09a0c
commit cafb1d0
Showing
4 changed files
with
184 additions
and
4 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
111 changes: 111 additions & 0 deletions
111
google/resource_compute_disk_resource_policy_attachment_generated_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,111 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
|
||
func TestAccComputeDiskResourcePolicyAttachment_diskResourcePolicyAttachmentBasicExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(10), | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckComputeDiskResourcePolicyAttachmentDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccComputeDiskResourcePolicyAttachment_diskResourcePolicyAttachmentBasicExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_compute_disk_resource_policy_attachment.attachment", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"disk", "zone"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccComputeDiskResourcePolicyAttachment_diskResourcePolicyAttachmentBasicExample(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_compute_disk_resource_policy_attachment" "attachment" { | ||
name = google_compute_resource_policy.policy.name | ||
disk = google_compute_disk.ssd.name | ||
zone = "us-central1-a" | ||
} | ||
resource "google_compute_disk" "ssd" { | ||
name = "my-disk%{random_suffix}" | ||
image = data.google_compute_image.my_image.self_link | ||
size = 50 | ||
type = "pd-ssd" | ||
zone = "us-central1-a" | ||
} | ||
resource "google_compute_resource_policy" "policy" { | ||
name = "my-resource-policy%{random_suffix}" | ||
region = "us-central1" | ||
snapshot_schedule_policy { | ||
schedule { | ||
daily_schedule { | ||
days_in_cycle = 1 | ||
start_time = "04:00" | ||
} | ||
} | ||
} | ||
} | ||
data "google_compute_image" "my_image" { | ||
family = "debian-9" | ||
project = "debian-cloud" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckComputeDiskResourcePolicyAttachmentDestroy(s *terraform.State) error { | ||
for name, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_compute_disk_resource_policy_attachment" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := testAccProvider.Meta().(*Config) | ||
|
||
url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/disks/{{disk}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequest(config, "GET", "", url, nil) | ||
if err == nil { | ||
return fmt.Errorf("ComputeDiskResourcePolicyAttachment still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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