Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

!!!
58 changes: 58 additions & 0 deletions examples/resources/cloud_project_instance/example_1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,61 @@ resource "ovh_cloud_project_instance" "instance" {
public = true
}
}


## with Multiple Network Interfaces

resource "ovh_cloud_project_network_private" "net_front" {
service_name = "XXX"
name = "public-front"
regions = ["GRA11"]
}

resource "ovh_cloud_project_subnet" "subnet_front" {
service_name = "XXX"
network_id = ovh_cloud_project_network_private.net_front.id
region = "GRA11"
network = "10.0.1.0/24"
dhcp = true
}

resource "ovh_cloud_project_network_private" "net_back" {
service_name = "XXX"
name = "private-back"
regions = ["GRA11"]
}

resource "ovh_cloud_project_subnet" "subnet_back" {
service_name = "XXX"
network_id = private.net_back.id
region = "GRA11"
network = "10.0.2.0/24"
dhcp = true
}

resource "ovh_cloud_project_instance" "multinic_instance" {
service_name = "XXX"
region = "GRA11"
name = "multi-nic-instance"
flavor_id = "UUID"
image_id = "UUID"

network {
public = true

private {
network {
id = private.net_front.id
subnet_id = subnet.subnet_front.id
}
ip = "10.0.1.10"
}

private {
network {
id = private.net_back.id
subnet_id = subnet.subnet_back.id
}
}
}
}
8 changes: 4 additions & 4 deletions ovh/resource_cloud_project_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func resourceCloudProjectInstance() *schema.Resource {
ForceNew: true,
},
"network": {
Type: schema.TypeSet,
Type: schema.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Expand All @@ -197,17 +197,15 @@ func resourceCloudProjectInstance() *schema.Resource {
Optional: true,
},
"private": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Description: "Private network information",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"floating_ip": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Description: "Existing floating IP",
ForceNew: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -425,12 +423,14 @@ func resourceCloudProjectInstance() *schema.Resource {
},
},
}

}

func resourceCloudProjectInstanceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
region := d.Get("region").(string)

params := new(CloudProjectInstanceCreateOpts)
params.FromResource(d)

Expand Down
115 changes: 115 additions & 0 deletions ovh/resource_cloud_project_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,118 @@ func TestAccCloudProjectInstance_privateNetworkAlreadyExists(t *testing.T) {
},
})
}

func TestAccCloudProjectInstance_multiNIC(t *testing.T) {
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")
region := os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST")
flavor, image, err := getFlavorAndImage(serviceName, region)
if err != nil {
t.Skipf("failed to retrieve a flavor and an image: %s", err)
}

rName := acctest.RandomWithPrefix(test_prefix)
netName1 := fmt.Sprintf("%s_net1", rName)
netName2 := fmt.Sprintf("%s_net2", rName)

vlanID1 := rand.Intn(2000) + 2
vlanID2 := vlanID1 + 1

var testCreateInstanceMultiNIC = fmt.Sprintf(`
resource "private" "net1" {
service_name = "%s"
name = "%s"
regions = ["%s"]
vlan_id = %d
}

resource "ovh_cloud_project_subnet" "sub1" {
service_name = "%s"
network_id = private.net1.id
region = "%s"
network = "192.168.1.0/24"
dhcp = true
start = "192.168.1.100"
end = "192.168.1.200"
no_gateway = false
}

resource "private" "net2" {
service_name = "%s"
name = "%s"
regions = ["%s"]
vlan_id = %d
}

resource "ovh_cloud_project_subnet" "sub2" {
service_name = "%s"
network_id = private.net2.id
region = "%s"
network = "192.168.2.0/24"
dhcp = true
start = "192.168.2.100"
end = "192.168.2.200"
no_gateway = false
}

resource "ovh_cloud_project_instance" "multi_nic" {
service_name = "%s"
region = "%s"
name = "%s"
billing_period = "hourly"

flavor {
flavor_id = "%s"
}
boot_from {
image_id = "%s"
}

network {
# Interface Publique
public = true

# Interface Privée 1
private {
network {
id = private.net1.id
subnet_id = ovh_cloud_project_subnet.sub1.id
}
}

# Interface Privée 2
private {
network {
id = private.net2.id
subnet_id = ovh_cloud_project_subnet.sub2.id
}
}
}
}
`,
serviceName, netName1, region, vlanID1,
serviceName, region,
serviceName, netName2, region, vlanID2,
serviceName, region,
serviceName, region, rName, flavor, image,
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckCloud(t)
testAccCheckCloudProjectExists(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testCreateInstanceMultiNIC,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.multi_nic", "id"),
resource.TestCheckResourceAttr("ovh_cloud_project_instance.multi_nic", "network.0.private.#", "2"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.multi_nic", "addresses.0.ip"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.multi_nic", "addresses.1.ip"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.multi_nic", "addresses.2.ip"),
),
},
},
})
}
Loading