-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathdata_source_mongodbatlas_network_containers_test.go
126 lines (109 loc) · 4.52 KB
/
data_source_mongodbatlas_network_containers_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
package mongodbatlas
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
matlas "go.mongodb.org/atlas/mongodbatlas"
)
func TestAccNetworkDSNetworkContainers_basic(t *testing.T) {
var container matlas.Container
randInt := acctest.RandIntRange(0, 255)
resourceName := "mongodbatlas_network_container.test"
cidrBlock := fmt.Sprintf("10.8.%d.0/24", randInt)
dataSourceName := "data.mongodbatlas_network_containers.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName := acctest.RandomWithPrefix("test-acc")
providerName := "AWS"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasNetworkContainerDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasNetworkContainersDSConfig(projectName, orgID, cidrBlock),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasNetworkContainerExists(resourceName, &container),
testAccCheckMongoDBAtlasNetworkContainerAttributes(&container, providerName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
resource.TestCheckResourceAttrSet(resourceName, "provisioned"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.#"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.id"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.atlas_cidr_block"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.provider_name"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.provisioned"),
),
},
},
})
}
func TestAccNetworkDSNetworkContainers_WithGCPRegions(t *testing.T) {
var container matlas.Container
randInt := acctest.RandIntRange(0, 255)
resourceName := "mongodbatlas_network_container.test"
cidrBlock := fmt.Sprintf("10.%d.0.0/21", randInt)
dataSourceName := "data.mongodbatlas_network_containers.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName := acctest.RandomWithPrefix("test-acc")
providerName := "GCP"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasNetworkContainerDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasNetworkContainersDSWithGCPRegionsConfig(projectName, orgID, cidrBlock),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasNetworkContainerExists(resourceName, &container),
testAccCheckMongoDBAtlasNetworkContainerAttributes(&container, providerName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "provider_name", providerName),
resource.TestCheckResourceAttrSet(resourceName, "provisioned"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.#"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.id"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.atlas_cidr_block"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.provider_name"),
resource.TestCheckResourceAttrSet(dataSourceName, "results.0.provisioned"),
),
},
},
})
}
func testAccMongoDBAtlasNetworkContainersDSConfig(projectName, orgID, cidrBlock string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = "%s"
org_id = "%s"
}
resource "mongodbatlas_network_container" "test" {
project_id = "${mongodbatlas_project.test.id}"
atlas_cidr_block = "%s"
provider_name = "AWS"
region_name = "US_EAST_1"
}
data "mongodbatlas_network_containers" "test" {
project_id = "${mongodbatlas_network_container.test.project_id}"
provider_name = "AWS"
}
`, projectName, orgID, cidrBlock)
}
func testAccMongoDBAtlasNetworkContainersDSWithGCPRegionsConfig(projectName, orgID, cidrBlock string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = "%s"
org_id = "%s"
}
resource "mongodbatlas_network_container" "test" {
project_id = mongodbatlas_project.test.id
atlas_cidr_block = "%s"
provider_name = "GCP"
regions = ["US_EAST_4", "US_WEST_3"]
}
data "mongodbatlas_network_containers" "test" {
project_id = mongodbatlas_network_container.test.project_id
provider_name = "GCP"
}
`, projectName, orgID, cidrBlock)
}