-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathresource_netapp_cloudmanager_aws_fsx_volume_test.go
127 lines (116 loc) · 3.44 KB
/
resource_netapp_cloudmanager_aws_fsx_volume_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package cloudmanager
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccFSXVolume_basic(t *testing.T) {
fileSystemID := "fs-wji22bngfx__3_1_183_4"
clientID := "vAWgtc8ZcLRshb08kybl2Uhh9W0o5ElE"
var volume volumeResponse
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckFSXVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccFSXVolumeConfigCreate(clientID, fileSystemID),
Check: resource.ComposeTestCheckFunc(
testAccCheckFSXVolumeExists("netapp-cloudmanager_aws_fsx_volume.nfs-volume-2", &volume),
),
},
},
})
}
func testAccCheckFSXVolumeDestroy(state *terraform.State) error {
client := testAccProvider.Meta().(*Client)
for _, rs := range state.RootModule().Resources {
fmt.Println(rs.Type)
if rs.Type != "netapp-cloudmanager_aws_fsx_volume" {
continue
}
var vol volumeRequest
vol.ID = rs.Primary.ID
vol.FileSystemID = rs.Primary.Attributes["file_system_id"]
vol.Name = rs.Primary.Attributes["name"]
var svm string
if v, ok := rs.Primary.Attributes["svm_name"]; ok {
svm = v
} else {
weInfo, err := client.getFSXWorkingEnvironmentInfo(rs.Primary.Attributes["tenant_id"], vol.FileSystemID, rs.Primary.Attributes["client_id"])
if err != nil {
return fmt.Errorf("Cannot find working environment")
}
svm = weInfo.SvmName
}
vol.SvmName = svm
response, err := client.getVolumeByID(vol, rs.Primary.Attributes["client_id"])
if err == nil {
if response.ID != "" {
return fmt.Errorf("volume (%s) still exists", response.ID)
}
}
}
return nil
}
func testAccCheckFSXVolumeExists(name string, volume *volumeResponse) resource.TestCheckFunc {
//time.Sleep(20 * time.Second)
return func(s *terraform.State) error {
// time.Sleep(20 * time.Second)
client := testAccProvider.Meta().(*Client)
rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No volume ID is set")
}
var vol volumeRequest
vol.ID = rs.Primary.ID
if v, ok := rs.Primary.Attributes["file_system_id"]; ok {
vol.FileSystemID = v
var svm string
if v2, ok := rs.Primary.Attributes["svm_name"]; ok {
svm = v2
} else {
weInfo, err := client.getFSXWorkingEnvironmentInfo(rs.Primary.Attributes["tenant_id"], v, rs.Primary.Attributes["client_id"])
if err != nil {
return fmt.Errorf("Cannot find working environment")
}
svm = weInfo.SvmName
}
volume.SvmName = svm
}
response, err := client.getVolumeByID(vol, rs.Primary.Attributes["client_id"])
if err != nil {
return err
}
if response.ID != rs.Primary.ID {
return fmt.Errorf("Resource ID and volume ID do not match")
}
*volume = response
return nil
}
}
func testAccFSXVolumeConfigCreate(clientID string, fileSystemID string) string {
return fmt.Sprintf(`
resource "netapp-cloudmanager_aws_fsx_volume" "nfs-volume-2" {
provider = netapp-cloudmanager
name = "acc_test_vol_2"
size = 10
unit = "GB"
svm_name = "svm_default"
enable_storage_efficiency = true
snapshot_policy_name = "default"
export_policy_type = "custom"
export_policy_ip = ["10.30.0.0/16"]
export_policy_nfs_version = ["nfs3", "nfs4"]
volume_protocol = "nfs"
client_id = "%s"
file_system_id = "%s"
tenant_id = "account-j3aZttuL"
}`, clientID, fileSystemID)
}