77
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1011)
1112
1213var testAccCloudProjectKubeIpRestrictionsConfig = `
@@ -26,6 +27,7 @@ resource "ovh_cloud_project_kube_iprestrictions" "iprestrictions" {
2627func TestAccCloudProjectKubeIpRestrictions_basic (t * testing.T ) {
2728 name := acctest .RandomWithPrefix (test_prefix )
2829 region := os .Getenv ("OVH_CLOUD_PROJECT_KUBE_REGION_TEST" )
30+ resourceName := "ovh_cloud_project_kube_iprestrictions.iprestrictions"
2931
3032 ips1 := `["10.42.0.0/16"]`
3133 config1 := fmt .Sprintf (
@@ -56,29 +58,29 @@ func TestAccCloudProjectKubeIpRestrictions_basic(t *testing.T) {
5658 {
5759 Config : config1 ,
5860 Check : resource .ComposeTestCheckFunc (
59- resource .TestCheckResourceAttr (
60- "ovh_cloud_project_kube.cluster" , "region" , region ),
61- resource .TestCheckResourceAttrSet (
62- "ovh_cloud_project_kube.cluster" , "kubeconfig" ),
63- resource .TestCheckResourceAttr (
64- "ovh_cloud_project_kube.cluster" , "name" , name ),
65- resource .TestCheckResourceAttr (
66- "ovh_cloud_project_kube_iprestrictions.iprestrictions" , "ips.0" , "10.42.0.0/16" ),
61+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube.cluster" , "region" , region ),
62+ resource .TestCheckResourceAttrSet ("ovh_cloud_project_kube.cluster" , "kubeconfig" ),
63+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube.cluster" , "name" , name ),
64+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube_iprestrictions.iprestrictions" , "ips.0" , "10.42.0.0/16" ),
6765 ),
6866 },
6967 {
7068 Config : config2 ,
7169 Check : resource .ComposeTestCheckFunc (
72- resource .TestCheckResourceAttr (
73- "ovh_cloud_project_kube.cluster" , "region" , region ),
74- resource .TestCheckResourceAttrSet (
75- "ovh_cloud_project_kube.cluster" , "kubeconfig" ),
76- resource .TestCheckResourceAttr (
77- "ovh_cloud_project_kube.cluster" , "name" , name ),
78- resource .TestCheckResourceAttr (
79- "ovh_cloud_project_kube_iprestrictions.iprestrictions" , "ips.1" , "10.43.0.0/16" ),
70+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube.cluster" , "region" , region ),
71+ resource .TestCheckResourceAttrSet ("ovh_cloud_project_kube.cluster" , "kubeconfig" ),
72+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube.cluster" , "name" , name ),
73+ resource .TestCheckResourceAttr ("ovh_cloud_project_kube_iprestrictions.iprestrictions" , "ips.1" , "10.43.0.0/16" ),
8074 ),
8175 },
76+ {
77+ ResourceName : resourceName ,
78+ ImportState : true ,
79+ ImportStateVerify : true ,
80+ ImportStateIdFunc : func (state * terraform.State ) (string , error ) {
81+ return fmt .Sprintf ("%s/%s" , os .Getenv ("OVH_CLOUD_PROJECT_SERVICE_TEST" ), state .RootModule ().Resources [resourceName ].Primary .ID ), nil
82+ },
83+ },
8284 },
8385 })
8486}
0 commit comments