Skip to content

Commit 49b5d61

Browse files
authored
Merge branch 'master' into fix/370
2 parents 00003c0 + eb6256f commit 49b5d61

13 files changed

+125
-76
lines changed

ovh/resource_cloud_project_kube_iprestrictions_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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

1213
var testAccCloudProjectKubeIpRestrictionsConfig = `
@@ -26,6 +27,7 @@ resource "ovh_cloud_project_kube_iprestrictions" "iprestrictions" {
2627
func 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
}

ovh/resource_cloud_project_kube_nodepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func resourceCloudProjectKubeNodePoolImportState(d *schema.ResourceData, meta in
219219
givenId := d.Id()
220220
splitId := strings.SplitN(givenId, "/", 3)
221221
if len(splitId) != 3 {
222-
return nil, fmt.Errorf("Import Id is not service_name/kubeid/poolid formatted")
222+
return nil, fmt.Errorf("import Id is not service_name/kubeid/poolid formatted")
223223
}
224224
serviceName := splitId[0]
225225
kubeId := splitId[1]

ovh/resource_cloud_project_kube_nodepool_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
13+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1314
)
1415

1516
func init() {
@@ -174,6 +175,7 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
174175
name := acctest.RandomWithPrefix(test_prefix)
175176
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
176177
version := os.Getenv("OVH_CLOUD_PROJECT_KUBE_VERSION_TEST")
178+
resourceName := "ovh_cloud_project_kube_nodepool.pool"
177179
config := fmt.Sprintf(
178180
testAccCloudProjectKubeNodePoolConfig,
179181
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
@@ -261,6 +263,16 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
261263
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
262264
),
263265
},
266+
{
267+
ResourceName: resourceName,
268+
ImportState: true,
269+
ImportStateVerify: true,
270+
ImportStateIdFunc: func(state *terraform.State) (string, error) {
271+
poolId := state.RootModule().Resources[resourceName].Primary.ID
272+
kubernetesClusterID := state.RootModule().Resources["ovh_cloud_project_kube.cluster"].Primary.ID
273+
return fmt.Sprintf("%s/%s/%s", os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"), kubernetesClusterID, poolId), nil
274+
},
275+
},
264276
},
265277
})
266278
}

ovh/resource_cloud_project_kube_oidc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ func resourceCloudProjectKubeOIDC() *schema.Resource {
9090

9191
func resourceCloudProjectKubeOIDCImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
9292
givenId := d.Id()
93+
log.Printf("[DEBUG] Importing cloud project kube OIDC %s", givenId)
94+
fmt.Sprintf("[DEBUG] Importing cloud project kube OIDC %s", givenId)
95+
9396
splitId := strings.SplitN(givenId, "/", 3)
9497
if len(splitId) != 2 {
95-
return nil, fmt.Errorf("Import Id is not service_name/kubeid formatted")
98+
return nil, fmt.Errorf("import Id is not service_name/kubeid formatted")
9699
}
97100
serviceName := splitId[0]
98-
kubeId := splitId[1]
99-
d.SetId(kubeId)
100-
d.Set("kube_id", kubeId)
101+
kubeID := splitId[1]
102+
d.SetId(serviceName + "/" + kubeID)
103+
d.Set("kube_id", kubeID)
101104
d.Set("service_name", serviceName)
102105

103106
results := make([]*schema.ResourceData, 1)

ovh/resource_cloud_project_kube_oidc_test.go

Lines changed: 32 additions & 42 deletions
Large diffs are not rendered by default.

ovh/resource_cloud_project_kube_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1616
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1717
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1819
)
1920

2021
func init() {
@@ -1009,6 +1010,7 @@ func TestAccCloudProjectKube_basic(t *testing.T) {
10091010
name := acctest.RandomWithPrefix(test_prefix)
10101011
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
10111012
version := os.Getenv("OVH_CLOUD_PROJECT_KUBE_VERSION_TEST")
1013+
resourceName := "ovh_cloud_project_kube.cluster"
10121014
config := fmt.Sprintf(
10131015
testAccCloudProjectKubeConfig,
10141016
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
@@ -1039,6 +1041,15 @@ func TestAccCloudProjectKube_basic(t *testing.T) {
10391041
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "kubeconfig_attributes.0.client_key"),
10401042
),
10411043
},
1044+
{
1045+
ResourceName: resourceName,
1046+
ImportState: true,
1047+
ImportStateVerify: true,
1048+
ImportStateIdFunc: func(state *terraform.State) (string, error) {
1049+
return fmt.Sprintf("%s/%s", os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"), state.RootModule().Resources[resourceName].Primary.ID), nil
1050+
},
1051+
ImportStateVerifyIgnore: []string{"kubeconfig"}, // we must ignore kubeconfig because certificate is not the same
1052+
},
10421053
},
10431054
})
10441055
}

ovh/resource_domain_zone_record.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func resourceOvhDomainZoneRecord() *schema.Resource {
7272
Type: schema.TypeInt,
7373
Optional: true,
7474
Default: 3600,
75+
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
76+
v := val.(int)
77+
if v < 60 {
78+
errs = append(errs, fmt.Errorf("%q must be greater than or equal to 60, got: %d", key, v))
79+
}
80+
return
81+
},
7582
},
7683
"fieldtype": {
7784
Type: schema.TypeString,

ovh/resource_domain_zone_record_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"strconv"
77
"testing"
88

9-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
10-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11-
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
129
"log"
10+
"regexp"
1311
"strings"
1412
"time"
13+
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
16+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1517
)
1618

1719
func init() {
@@ -103,6 +105,11 @@ func TestAccDomainZoneRecord_Basic(t *testing.T) {
103105
Providers: testAccProviders,
104106
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
105107
Steps: []resource.TestStep{
108+
// provider shall send an error if the TTL is less than 60
109+
{
110+
Config: testAccCheckOvhDomainZoneRecordConfig_CNAME(zone, subdomain, "google.com.", 10),
111+
ExpectError: regexp.MustCompile(`must be greater`),
112+
},
106113
{
107114
Config: testAccCheckOvhDomainZoneRecordConfig_A(zone, subdomain, "192.168.0.10", 3600),
108115
Check: resource.ComposeTestCheckFunc(

ovh/resource_ip_reverse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func testAccIpReverseImportId(resourceName string) resource.ImportStateIdFunc {
122122
}
123123

124124
return fmt.Sprintf(
125-
"%s:%s",
125+
"%s|%s",
126126
subnet.Primary.Attributes["ip"],
127127
subnet.Primary.Attributes["ip_reverse"],
128128
), nil

website/docs/r/cloud_project_kube.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ resource "ovh_cloud_project_kube" "mycluster" {
8181
provider "helm" {
8282
kubernetes {
8383
host = ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].host
84-
client_certificate = ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].client_certificate
85-
client_key = ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].client_key
86-
cluster_ca_certificate = ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].cluster_ca_certificate
84+
client_certificate = base64decode(ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].client_certificate)
85+
client_key = base64decode(ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].client_key)
86+
cluster_ca_certificate = base64decode(ovh_cloud_project_kube.mycluster.kubeconfig_attributes[0].cluster_ca_certificate)
8787
}
8888
}
8989

0 commit comments

Comments
 (0)