-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathdata_source_mongodbatlas_privatelink_endpoint_service_serverless_test.go
114 lines (92 loc) · 3.51 KB
/
data_source_mongodbatlas_privatelink_endpoint_service_serverless_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
package mongodbatlas
import (
"context"
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccDataSourceMongoDBAtlasPrivateLinkEndpointServiceServerless_basic(t *testing.T) {
var (
resourceName = "data.mongodbatlas_privatelink_endpoint_service_serverless.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
instanceName = "dsserverless"
commentOrigin = "create"
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, commentOrigin),
Check: resource.ComposeTestCheckFunc(
testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "comment", commentOrigin),
),
},
},
})
}
func testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessDestroy(state *terraform.State) error {
conn := testAccProvider.Meta().(*MongoDBClient).Atlas
for _, rs := range state.RootModule().Resources {
if rs.Type != "data.mongodbatlas_privatelink_endpoint_service_serverless" {
continue
}
ids := decodeStateID(rs.Primary.ID)
privateLink, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"])
if err == nil && privateLink != nil {
return fmt.Errorf("endpoint_id (%s) still exists", ids["endpoint_id"])
}
}
return nil
}
func testAccDSMongoDBAtlasPrivateLinkEndpointServiceServerlessConfig(projectID, instanceName, comment string) string {
return fmt.Sprintf(`
data "mongodbatlas_privatelink_endpoint_service_serverless" "test" {
project_id = "%[1]s"
instance_name = mongodbatlas_serverless_instance.test.name
endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id
}
resource "mongodbatlas_privatelink_endpoint_serverless" "test" {
project_id = "%[1]s"
instance_name = mongodbatlas_serverless_instance.test.name
provider_name = "AWS"
}
resource "mongodbatlas_privatelink_endpoint_service_serverless" "test" {
project_id = "%[1]s"
instance_name = "%[2]s"
endpoint_id = mongodbatlas_privatelink_endpoint_serverless.test.endpoint_id
provider_name = "AWS"
comment = "%[3]s"
}
resource "mongodbatlas_serverless_instance" "test" {
project_id = "%[1]s"
name = "%[2]s"
provider_settings_backing_provider_name = "AWS"
provider_settings_provider_name = "SERVERLESS"
provider_settings_region_name = "US_EAST_1"
continuous_backup_enabled = true
}
`, projectID, instanceName, comment)
}
func testAccDSCheckMongoDBAtlasPrivateLinkEndpointServiceServerlessExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*MongoDBClient).Atlas
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("not found: %s", resourceName)
}
if rs.Primary.ID == "" {
return fmt.Errorf("no ID is set")
}
ids := decodeStateID(rs.Primary.ID)
_, _, err := conn.ServerlessPrivateEndpoints.Get(context.Background(), ids["project_id"], ids["instance_name"], ids["endpoint_id"])
if err == nil {
return nil
}
return fmt.Errorf("endpoint_id (%s) does not exist", ids["endpoint_id"])
}
}