Skip to content

Commit 7480742

Browse files
authored
Merge pull request #310 from ovh/fix-acceptance-test-TestAccCloudProjectKubeVRack
fix: TestAccCloudProjectKubeVRack acceptance test
2 parents 5f5b174 + 017e3a9 commit 7480742

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

ovh/provider_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ func testAccPreCheckKubernetes(t *testing.T) {
160160
checkEnvOrSkip(t, "OVH_CLOUD_PROJECT_KUBE_VERSION_TEST")
161161
}
162162

163+
// Checks that the environment variables needed for the /vrack/{service}/cloudProject acceptance tests
164+
// are set.
165+
func testAccPreCheckKubernetesVRack(t *testing.T) {
166+
testAccPreCheckCredentials(t)
167+
checkEnvOrSkip(t, "OVH_VRACK_SERVICE_TEST")
168+
}
169+
163170
// Checks that the environment variables needed for the /ipLoadbalacing acceptance tests
164171
// are set.
165172
func testAccPreCheckIpLoadbalancing(t *testing.T) {

ovh/resource_cloud_project_kube_test.go

+32-26
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,48 @@ resource "ovh_cloud_project_kube" "cluster" {
9595
`
9696

9797
var testAccCloudProjectKubeVRackConfig = `
98-
resource "ovh_cloud_project_network_private" "network1" {
98+
resource "ovh_vrack_cloudproject" "attach" {
99+
service_name = "{{ .VrackID }}"
100+
project_id = "{{ .ServiceName }}"
101+
}
102+
103+
resource "ovh_cloud_project_network_private" "network" {
99104
service_name = "{{ .ServiceName }}"
100-
name = "dhcp-default-gateway"
101-
regions = {{ .Regions }}
102-
vlan_id = "{{ .Vlanid }}"
105+
vlan_id = 0
106+
name = "terraform_testacc_private_net"
107+
regions = ["{{ .Region }}"]
108+
depends_on = [ovh_vrack_cloudproject.attach]
103109
}
104110
105-
resource "ovh_cloud_project_network_private_subnet" "network1subnetSBG5" {
106-
service_name = "{{ .ServiceName }}"
107-
network_id = ovh_cloud_project_network_private.network1.id
108-
start = "10.6.0.2" #first ip is burn for gateway ip
109-
end = "10.6.255.254"
110-
network = "10.6.0.0/16"
111-
dhcp = true
112-
region = "{{ .Region }}"
113-
no_gateway = false
114-
depends_on = [ovh_cloud_project_network_private.network1]
111+
resource "ovh_cloud_project_network_private_subnet" "networksubnet" {
112+
service_name = ovh_cloud_project_network_private.network.service_name
113+
network_id = ovh_cloud_project_network_private.network.id
114+
115+
# whatever region, for test purpose
116+
region = "{{ .Region }}"
117+
start = "192.168.168.100"
118+
end = "192.168.168.200"
119+
network = "192.168.168.0/24"
120+
dhcp = true
121+
no_gateway = false
122+
123+
depends_on = [ovh_cloud_project_network_private.network]
115124
}
116125
117126
resource "ovh_cloud_project_kube" "cluster" {
118127
service_name = "{{ .ServiceName }}"
119128
name = "{{ .Name }}"
120129
region = "{{ .Region }}"
121130
122-
private_network_id = tolist(ovh_cloud_project_network_private.network1.regions_attributes)[index(ovh_cloud_project_network_private.network1.regions_attributes.*.region, "{{ .Region }}")].openstackid
131+
private_network_id = tolist(ovh_cloud_project_network_private.network.regions_attributes[*].openstackid)[0]
123132
124133
private_network_configuration {
125134
default_vrack_gateway = "{{ .DefaultVrackGateway }}"
126135
private_network_routing_as_default = {{ .PrivateNetworkRoutingAsDefault }}
127136
}
128137
129138
depends_on = [
130-
ovh_cloud_project_network_private.network1
139+
ovh_cloud_project_network_private.network
131140
]
132141
}
133142
`
@@ -166,8 +175,8 @@ resource "ovh_cloud_project_kube" "cluster" {
166175
type configData struct {
167176
Region string
168177
Regions string
169-
Vlanid string
170178
ServiceName string
179+
VrackID string
171180
Name string
172181
DefaultVrackGateway string
173182
PrivateNetworkRoutingAsDefault bool
@@ -221,8 +230,8 @@ func TestAccCloudProjectKubeCustomizationApiServerAdmissionPlugins(t *testing.T)
221230
}
222231

223232
func TestAccCloudProjectKubeVRack(t *testing.T) {
224-
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
225233
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")
234+
vrackID := os.Getenv("OVH_VRACK_SERVICE_TEST")
226235

227236
name := acctest.RandomWithPrefix(test_prefix)
228237
tmpl, err := template.New("config").Parse(testAccCloudProjectKubeVRackConfig)
@@ -233,20 +242,18 @@ func TestAccCloudProjectKubeVRack(t *testing.T) {
233242
var config bytes.Buffer
234243
var configUpdated bytes.Buffer
235244
configData1 := configData{
236-
Region: region,
237-
Regions: `["` + region + `"]`,
238-
Vlanid: "8",
239245
ServiceName: serviceName,
246+
VrackID: vrackID,
240247
Name: name,
248+
Region: "GRA5",
241249
DefaultVrackGateway: "",
242250
PrivateNetworkRoutingAsDefault: false,
243251
}
244252
configData2 := configData{
245-
Region: region,
246-
Regions: `["` + region + `"]`,
247-
Vlanid: "8",
248253
ServiceName: serviceName,
254+
VrackID: vrackID,
249255
Name: name,
256+
Region: "GRA5",
250257
DefaultVrackGateway: "10.4.0.1",
251258
PrivateNetworkRoutingAsDefault: true,
252259
}
@@ -266,13 +273,13 @@ func TestAccCloudProjectKubeVRack(t *testing.T) {
266273
testAccPreCheckCloud(t)
267274
testAccCheckCloudProjectExists(t)
268275
testAccPreCheckKubernetes(t)
276+
testAccPreCheckKubernetesVRack(t)
269277
},
270278
Providers: testAccProviders,
271279
Steps: []resource.TestStep{
272280
{
273281
Config: config.String(),
274282
Check: resource.ComposeTestCheckFunc(
275-
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", "region", region),
276283
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "kubeconfig"),
277284
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", kubeClusterNameKey, name),
278285
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "version"),
@@ -283,7 +290,6 @@ func TestAccCloudProjectKubeVRack(t *testing.T) {
283290
{
284291
Config: configUpdated.String(),
285292
Check: resource.ComposeTestCheckFunc(
286-
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", "region", region),
287293
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "kubeconfig"),
288294
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", kubeClusterNameKey, name),
289295
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "version"),

0 commit comments

Comments
 (0)