|
| 1 | +package scaleway |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAccScalewayDataSourceIPAMIP_Instance(t *testing.T) { |
| 10 | + tt := NewTestTools(t) |
| 11 | + defer tt.Cleanup() |
| 12 | + resource.ParallelTest(t, resource.TestCase{ |
| 13 | + PreCheck: func() { testAccPreCheck(t) }, |
| 14 | + ProviderFactories: tt.ProviderFactories, |
| 15 | + CheckDestroy: testAccCheckScalewayInstanceServerDestroy(tt), |
| 16 | + Steps: []resource.TestStep{ |
| 17 | + { |
| 18 | + Config: ` |
| 19 | + resource "scaleway_vpc" "main" { |
| 20 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 21 | + } |
| 22 | +
|
| 23 | + resource "scaleway_vpc_private_network" "main" { |
| 24 | + vpc_id = scaleway_vpc.main.id |
| 25 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 26 | + } |
| 27 | +
|
| 28 | + resource "scaleway_instance_server" "main" { |
| 29 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 30 | + image = "ubuntu_jammy" |
| 31 | + type = "PLAY2-MICRO" |
| 32 | + tags = [ "terraform-test", "data_scaleway_instance_servers", "basic" ] |
| 33 | + } |
| 34 | +
|
| 35 | + resource "scaleway_instance_private_nic" "main" { |
| 36 | + private_network_id = scaleway_vpc_private_network.main.id |
| 37 | + server_id = scaleway_instance_server.main.id |
| 38 | + } |
| 39 | +
|
| 40 | + data "scaleway_ipam_ip" "main" { |
| 41 | + mac_address = scaleway_instance_private_nic.main.mac_address |
| 42 | + type = "ipv4" |
| 43 | + }`, |
| 44 | + Check: resource.ComposeTestCheckFunc( |
| 45 | + resource.TestCheckResourceAttrSet("data.scaleway_ipam_ip.main", "address"), |
| 46 | + ), |
| 47 | + }, |
| 48 | + }, |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +func TestAccScalewayDataSourceIPAMIP_InstanceLB(t *testing.T) { |
| 53 | + tt := NewTestTools(t) |
| 54 | + defer tt.Cleanup() |
| 55 | + resource.ParallelTest(t, resource.TestCase{ |
| 56 | + PreCheck: func() { testAccPreCheck(t) }, |
| 57 | + ProviderFactories: tt.ProviderFactories, |
| 58 | + CheckDestroy: testAccCheckScalewayInstanceServerDestroy(tt), |
| 59 | + Steps: []resource.TestStep{ |
| 60 | + { |
| 61 | + Config: ` |
| 62 | + resource "scaleway_vpc" "main" { |
| 63 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 64 | + } |
| 65 | +
|
| 66 | + resource "scaleway_vpc_private_network" "main" { |
| 67 | + vpc_id = scaleway_vpc.main.id |
| 68 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 69 | + } |
| 70 | +
|
| 71 | + resource "scaleway_instance_server" "main" { |
| 72 | + name = "tf-tests-ipam-ip-datasource-instance" |
| 73 | + image = "ubuntu_jammy" |
| 74 | + type = "PLAY2-MICRO" |
| 75 | + tags = [ "terraform-test", "data_scaleway_instance_servers", "basic" ] |
| 76 | + } |
| 77 | +
|
| 78 | + resource "scaleway_instance_private_nic" "main" { |
| 79 | + private_network_id = scaleway_vpc_private_network.main.id |
| 80 | + server_id = scaleway_instance_server.main.id |
| 81 | + } |
| 82 | +
|
| 83 | + data "scaleway_ipam_ip" "main" { |
| 84 | + mac_address = scaleway_instance_private_nic.main.mac_address |
| 85 | + type = "ipv4" |
| 86 | + } |
| 87 | +
|
| 88 | + resource "scaleway_lb_ip" "main" {} |
| 89 | +
|
| 90 | + resource "scaleway_lb" "main" { |
| 91 | + ip_id = scaleway_lb_ip.main.id |
| 92 | + type = "LB-S" |
| 93 | + } |
| 94 | + |
| 95 | + resource "scaleway_lb_backend" "main" { |
| 96 | + lb_id = scaleway_lb.main.id |
| 97 | + forward_protocol = "http" |
| 98 | + forward_port = "80" |
| 99 | + server_ips = [data.scaleway_ipam_ip.main.address] |
| 100 | + }`, |
| 101 | + Check: resource.ComposeTestCheckFunc( |
| 102 | + resource.TestCheckResourceAttrSet("data.scaleway_ipam_ip.main", "address"), |
| 103 | + ), |
| 104 | + }, |
| 105 | + }, |
| 106 | + }) |
| 107 | +} |
0 commit comments