|
1 | 1 | package instance_test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "errors" |
6 | 5 | "fmt" |
7 | 6 | "regexp" |
8 | 7 | "strings" |
9 | 8 | "testing" |
10 | 9 |
|
11 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
12 | | - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
13 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
14 | 12 | instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1" |
15 | 13 | "github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest" |
16 | 14 | "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality" |
17 | 15 | "github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal" |
18 | | - "github.com/scaleway/terraform-provider-scaleway/v2/internal/meta" |
19 | | - "github.com/scaleway/terraform-provider-scaleway/v2/internal/provider" |
20 | 16 | "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance" |
21 | 17 | instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs" |
22 | | - "github.com/stretchr/testify/require" |
23 | 18 | ) |
24 | 19 |
|
25 | 20 | func TestAccServer_Minimal1(t *testing.T) { |
@@ -731,36 +726,34 @@ func TestAccServer_Ipv6(t *testing.T) { |
731 | 726 | Steps: []resource.TestStep{ |
732 | 727 | { |
733 | 728 | Config: ` |
| 729 | + resource "scaleway_instance_ip" "ip" { |
| 730 | + type = "routed_ipv6" |
| 731 | + } |
| 732 | +
|
734 | 733 | resource "scaleway_instance_server" "server01" { |
735 | 734 | image = "ubuntu_focal" |
736 | | - type = "DEV1-S" |
737 | | - enable_ipv6 = true |
738 | | - routed_ip_enabled = false |
| 735 | + type = "PLAY2-PICO" |
| 736 | + ip_ids = [scaleway_instance_ip.ip.id] |
739 | 737 | } |
740 | 738 | `, |
741 | 739 | Check: resource.ComposeTestCheckFunc( |
742 | 740 | isServerPresent(tt, "scaleway_instance_server.server01"), |
743 | | - // enable_ipv6, ipv6_address and ipv6_gateway are marked as deprecated |
744 | | - resource.TestCheckResourceAttr("scaleway_instance_server.server01", "enable_ipv6", "true"), |
745 | | - acctest.CheckResourceAttrIPv6("scaleway_instance_server.server01", "ipv6_address"), |
746 | | - acctest.CheckResourceAttrIPv6("scaleway_instance_server.server01", "ipv6_gateway"), |
747 | | - resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_prefix_length", "64"), |
| 741 | + acctest.CheckResourceAttrIPv6("scaleway_instance_server.server01", "public_ips.0.address"), |
748 | 742 | ), |
749 | 743 | }, |
750 | 744 | { |
751 | 745 | Config: ` |
752 | 746 | resource "scaleway_instance_server" "server01" { |
753 | 747 | image = "ubuntu_focal" |
754 | | - type = "DEV1-S" |
755 | | - enable_ipv6 = false |
756 | | - routed_ip_enabled = false |
| 748 | + type = "PLAY2-PICO" |
757 | 749 | } |
758 | 750 | `, |
759 | 751 | Check: resource.ComposeTestCheckFunc( |
760 | 752 | isServerPresent(tt, "scaleway_instance_server.server01"), |
761 | 753 | resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_address", ""), |
762 | 754 | resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_gateway", ""), |
763 | 755 | resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_prefix_length", "0"), |
| 756 | + resource.TestCheckResourceAttr("scaleway_instance_server.server01", "public_ips.#", "0"), |
764 | 757 | ), |
765 | 758 | }, |
766 | 759 | }, |
@@ -1496,94 +1489,6 @@ func serverIDsAreDifferent(nameFirst, nameSecond string) resource.TestCheckFunc |
1496 | 1489 | } |
1497 | 1490 | } |
1498 | 1491 |
|
1499 | | -func TestAccServer_RoutedIPEnable(t *testing.T) { |
1500 | | - tt := acctest.NewTestTools(t) |
1501 | | - defer tt.Cleanup() |
1502 | | - resource.ParallelTest(t, resource.TestCase{ |
1503 | | - PreCheck: func() { acctest.PreCheck(t) }, |
1504 | | - ProviderFactories: tt.ProviderFactories, |
1505 | | - CheckDestroy: instancechecks.IsServerDestroyed(tt), |
1506 | | - Steps: []resource.TestStep{ |
1507 | | - { |
1508 | | - Config: ` |
1509 | | - resource "scaleway_instance_server" "main" { |
1510 | | - name = "tf-tests-instance-server-routedip" |
1511 | | - image = "ubuntu_jammy" |
1512 | | - type = "PRO2-XXS" |
1513 | | - state = "stopped" |
1514 | | - routed_ip_enabled = false |
1515 | | - }`, |
1516 | | - Check: resource.ComposeTestCheckFunc( |
1517 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1518 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "false"), |
1519 | | - ), |
1520 | | - }, |
1521 | | - { |
1522 | | - Config: ` |
1523 | | - resource "scaleway_instance_server" "main" { |
1524 | | - name = "tf-tests-instance-server-routedip" |
1525 | | - image = "ubuntu_jammy" |
1526 | | - type = "PRO2-XXS" |
1527 | | - routed_ip_enabled = true |
1528 | | - state = "stopped" |
1529 | | - }`, |
1530 | | - Check: resource.ComposeTestCheckFunc( |
1531 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1532 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"), |
1533 | | - ), |
1534 | | - }, |
1535 | | - }, |
1536 | | - }) |
1537 | | -} |
1538 | | - |
1539 | | -func TestAccServer_RoutedIPEnableWithIP(t *testing.T) { |
1540 | | - tt := acctest.NewTestTools(t) |
1541 | | - defer tt.Cleanup() |
1542 | | - resource.ParallelTest(t, resource.TestCase{ |
1543 | | - PreCheck: func() { acctest.PreCheck(t) }, |
1544 | | - ProviderFactories: tt.ProviderFactories, |
1545 | | - CheckDestroy: instancechecks.IsServerDestroyed(tt), |
1546 | | - Steps: []resource.TestStep{ |
1547 | | - { |
1548 | | - Config: ` |
1549 | | - resource "scaleway_instance_ip" "main" { |
1550 | | - type = "nat" |
1551 | | - } |
1552 | | -
|
1553 | | - resource "scaleway_instance_server" "main" { |
1554 | | - name = "tf-tests-instance-server-routedip-enable-with-ip" |
1555 | | - ip_id = scaleway_instance_ip.main.id |
1556 | | - image = "ubuntu_jammy" |
1557 | | - type = "PRO2-XXS" |
1558 | | - state = "stopped" |
1559 | | - routed_ip_enabled = false |
1560 | | - }`, |
1561 | | - Check: resource.ComposeTestCheckFunc( |
1562 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1563 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "false"), |
1564 | | - ), |
1565 | | - }, |
1566 | | - { |
1567 | | - Config: ` |
1568 | | - resource "scaleway_instance_ip" "main" {} |
1569 | | -
|
1570 | | - resource "scaleway_instance_server" "main" { |
1571 | | - name = "tf-tests-instance-server-routedip-enable-with-ip" |
1572 | | - ip_id = scaleway_instance_ip.main.id |
1573 | | - image = "ubuntu_jammy" |
1574 | | - type = "PRO2-XXS" |
1575 | | - state = "stopped" |
1576 | | - routed_ip_enabled = true |
1577 | | - }`, |
1578 | | - Check: resource.ComposeTestCheckFunc( |
1579 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1580 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"), |
1581 | | - ), |
1582 | | - }, |
1583 | | - }, |
1584 | | - }) |
1585 | | -} |
1586 | | - |
1587 | 1492 | func TestAccServer_IPs(t *testing.T) { |
1588 | 1493 | tt := acctest.NewTestTools(t) |
1589 | 1494 | defer tt.Cleanup() |
@@ -1762,178 +1667,6 @@ func TestAccServer_IPsRemoved(t *testing.T) { |
1762 | 1667 | }) |
1763 | 1668 | } |
1764 | 1669 |
|
1765 | | -func TestAccServer_IPMigrate(t *testing.T) { |
1766 | | - tt := acctest.NewTestTools(t) |
1767 | | - defer tt.Cleanup() |
1768 | | - |
1769 | | - ctx := context.Background() |
1770 | | - // This come from iam_policy tests to use policies in tests |
1771 | | - project, iamAPIKey, terminateFakeSideProject, err := acctest.CreateFakeIAMManager(tt) |
1772 | | - require.NoError(t, err) |
1773 | | - |
1774 | | - // This is the provider factory that will use the temporary project |
1775 | | - providerFactories := acctest.FakeSideProjectProviders(ctx, tt, project, iamAPIKey) |
1776 | | - |
1777 | | - // Goal of this test is to check that an IP will not get detached if moved from ip_id to ip_ids |
1778 | | - // Between the two steps we will create an API key that cannot update the IP, |
1779 | | - // it should fail if the provider tries to detach |
1780 | | - temporaryAccessKey := "" |
1781 | | - temporarySecretKey := "" |
1782 | | - customProviderFactory := map[string]func() (*schema.Provider, error){ |
1783 | | - "scaleway": func() (*schema.Provider, error) { |
1784 | | - m, err := meta.NewMeta(context.Background(), &meta.Config{ |
1785 | | - ProviderSchema: nil, |
1786 | | - TerraformVersion: "terraform-tests", |
1787 | | - HTTPClient: tt.Meta.HTTPClient(), |
1788 | | - ForceAccessKey: temporaryAccessKey, |
1789 | | - ForceSecretKey: temporarySecretKey, |
1790 | | - }) |
1791 | | - if err != nil { |
1792 | | - return nil, err |
1793 | | - } |
1794 | | - return provider.Provider(&provider.Config{Meta: m})(), nil |
1795 | | - }, |
1796 | | - } |
1797 | | - |
1798 | | - resource.ParallelTest(t, resource.TestCase{ |
1799 | | - PreCheck: func() { acctest.PreCheck(t) }, |
1800 | | - CheckDestroy: resource.ComposeAggregateTestCheckFunc( |
1801 | | - func(_ *terraform.State) error { |
1802 | | - return terminateFakeSideProject() |
1803 | | - }, |
1804 | | - instancechecks.IsServerDestroyed(tt), |
1805 | | - ), |
1806 | | - Steps: []resource.TestStep{ |
1807 | | - { |
1808 | | - ProviderFactories: providerFactories, |
1809 | | - Config: fmt.Sprintf(` |
1810 | | - resource "scaleway_instance_ip" "ip" { |
1811 | | - type = "nat" |
1812 | | - } |
1813 | | -
|
1814 | | - resource "scaleway_instance_server" "main" { |
1815 | | - ip_id = scaleway_instance_ip.ip.id |
1816 | | - image = "ubuntu_jammy" |
1817 | | - type = "PRO2-XXS" |
1818 | | - state = "stopped" |
1819 | | - routed_ip_enabled = false |
1820 | | - } |
1821 | | -
|
1822 | | - resource "scaleway_iam_application" "app" { |
1823 | | - name = "tf_tests_instance_server_ipmigrate" |
1824 | | - } |
1825 | | -
|
1826 | | - resource "scaleway_iam_policy" "policy" { |
1827 | | - application_id = scaleway_iam_application.app.id |
1828 | | - rule { |
1829 | | - permission_set_names = ["InstancesReadOnly"] |
1830 | | - organization_id = %[1]q |
1831 | | - } |
1832 | | - rule { |
1833 | | - permission_set_names = ["ProjectReadOnly", "IAMReadOnly"] |
1834 | | - organization_id = %[1]q |
1835 | | - } |
1836 | | - } |
1837 | | -
|
1838 | | - resource "scaleway_iam_api_key" "key" { |
1839 | | - application_id = scaleway_iam_application.app.id |
1840 | | - }`, project.OrganizationID), |
1841 | | - Check: resource.ComposeTestCheckFunc( |
1842 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1843 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "false"), |
1844 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"), |
1845 | | - func(s *terraform.State) error { |
1846 | | - rs, ok := s.RootModule().Resources["scaleway_iam_api_key.key"] |
1847 | | - if !ok { |
1848 | | - return fmt.Errorf("resource was not found: %s", "scaleway_iam_api_key.key") |
1849 | | - } |
1850 | | - temporaryAccessKey = rs.Primary.Attributes["access_key"] |
1851 | | - temporarySecretKey = rs.Primary.Attributes["secret_key"] |
1852 | | - |
1853 | | - return nil |
1854 | | - }, |
1855 | | - ), |
1856 | | - }, |
1857 | | - { |
1858 | | - ProviderFactories: customProviderFactory, |
1859 | | - // With migration supported, this should make no changes |
1860 | | - // This is validated because we cannot add a nat IP to ip_ids |
1861 | | - // This would fail if not moved from ip_id to ip_ids |
1862 | | - Config: fmt.Sprintf(` |
1863 | | - resource "scaleway_instance_ip" "ip" { |
1864 | | - type = "nat" |
1865 | | - } |
1866 | | -
|
1867 | | - resource "scaleway_instance_server" "main" { |
1868 | | - ip_ids = [scaleway_instance_ip.ip.id] |
1869 | | - image = "ubuntu_jammy" |
1870 | | - type = "PRO2-XXS" |
1871 | | - state = "stopped" |
1872 | | - } |
1873 | | -
|
1874 | | - resource "scaleway_iam_application" "app" { |
1875 | | - name = "tf_tests_instance_server_ipmigrate" |
1876 | | - } |
1877 | | -
|
1878 | | - resource "scaleway_iam_policy" "policy" { |
1879 | | - application_id = scaleway_iam_application.app.id |
1880 | | - rule { |
1881 | | - permission_set_names = ["InstancesReadOnly"] |
1882 | | - organization_id = %[1]q |
1883 | | - } |
1884 | | - rule { |
1885 | | - permission_set_names = ["ProjectReadOnly", "IAMReadOnly"] |
1886 | | - organization_id = %[1]q |
1887 | | - } |
1888 | | - } |
1889 | | -
|
1890 | | - resource "scaleway_iam_api_key" "key" { |
1891 | | - application_id = scaleway_iam_application.app.id |
1892 | | - }`, project.OrganizationID), |
1893 | | - Check: resource.ComposeTestCheckFunc( |
1894 | | - arePrivateNICsPresent(tt, "scaleway_instance_server.main"), |
1895 | | - resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"), |
1896 | | - ), |
1897 | | - }, |
1898 | | - { |
1899 | | - ProviderFactories: tt.ProviderFactories, |
1900 | | - // Last step with default api key to remove resources |
1901 | | - Config: fmt.Sprintf(` |
1902 | | - resource "scaleway_instance_ip" "ip" { |
1903 | | - type = "nat" |
1904 | | - } |
1905 | | -
|
1906 | | - resource "scaleway_instance_server" "main" { |
1907 | | - ip_ids = [scaleway_instance_ip.ip.id] |
1908 | | - image = "ubuntu_jammy" |
1909 | | - type = "PRO2-XXS" |
1910 | | - state = "stopped" |
1911 | | - } |
1912 | | -
|
1913 | | - resource "scaleway_iam_application" "app" { |
1914 | | - name = "tf_tests_instance_server_ipmigrate" |
1915 | | - } |
1916 | | -
|
1917 | | - resource "scaleway_iam_policy" "policy" { |
1918 | | - application_id = scaleway_iam_application.app.id |
1919 | | - rule { |
1920 | | - permission_set_names = ["InstancesReadOnly"] |
1921 | | - organization_id = %[1]q |
1922 | | - } |
1923 | | - rule { |
1924 | | - permission_set_names = ["ProjectReadOnly", "IAMReadOnly"] |
1925 | | - organization_id = %[1]q |
1926 | | - } |
1927 | | - } |
1928 | | -
|
1929 | | - resource "scaleway_iam_api_key" "key" { |
1930 | | - application_id = scaleway_iam_application.app.id |
1931 | | - }`, project.OrganizationID), |
1932 | | - }, |
1933 | | - }, |
1934 | | - }) |
1935 | | -} |
1936 | | - |
1937 | 1670 | func TestAccServer_BlockExternal(t *testing.T) { |
1938 | 1671 | tt := acctest.NewTestTools(t) |
1939 | 1672 | defer tt.Cleanup() |
|
0 commit comments