Skip to content

Commit db1dc2f

Browse files
author
mathieu prigent
committed
fix import kube oidc
1 parent 1a09362 commit db1dc2f

3 files changed

+35
-9
lines changed

ovh/resource_cloud_project_kube_oidc.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ovh
33
import (
44
"fmt"
55
"log"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
)
@@ -14,7 +15,7 @@ func resourceCloudProjectKubeOIDC() *schema.Resource {
1415
Delete: resourceCloudProjectKubeOIDCDelete,
1516
Update: resourceCloudProjectKubeOIDCUpdate,
1617
Importer: &schema.ResourceImporter{
17-
State: schema.ImportStatePassthrough,
18+
State: resourceCloudProjectKubeOIDCImportState,
1819
},
1920

2021
Schema: map[string]*schema.Schema{
@@ -79,6 +80,23 @@ func resourceCloudProjectKubeOIDC() *schema.Resource {
7980
}
8081
}
8182

83+
func resourceCloudProjectKubeOIDCImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
84+
givenId := d.Id()
85+
splitId := strings.SplitN(givenId, "/", 3)
86+
if len(splitId) != 2 {
87+
return nil, fmt.Errorf("Import Id is not service_name/kubeid formatted")
88+
}
89+
serviceName := splitId[0]
90+
kubeId := splitId[1]
91+
d.SetId(kubeId)
92+
d.Set("kube_id", kubeId)
93+
d.Set("service_name", serviceName)
94+
95+
results := make([]*schema.ResourceData, 1)
96+
results[0] = d
97+
return results, nil
98+
}
99+
82100
func resourceCloudProjectKubeOIDCCreate(d *schema.ResourceData, meta interface{}) error {
83101
config := meta.(*Config)
84102

@@ -95,7 +113,7 @@ func resourceCloudProjectKubeOIDCCreate(d *schema.ResourceData, meta interface{}
95113
return fmt.Errorf("calling Post %s with params %s:\n\t %w", endpoint, params, err)
96114
}
97115

98-
d.SetId(kubeID + "-" + params.ClientID + "-" + params.IssuerUrl)
116+
d.SetId(serviceName + "/" + kubeID)
99117

100118
log.Printf("[DEBUG] Waiting for kube %s to be READY", kubeID)
101119
err = waitForCloudProjectKubeReady(config.OVHClient, serviceName, kubeID, []string{"REDEPLOYING"}, []string{"READY"})
@@ -125,7 +143,7 @@ func resourceCloudProjectKubeOIDCRead(d *schema.ResourceData, meta interface{})
125143
if k != "id" {
126144
d.Set(k, v)
127145
} else {
128-
d.SetId(kubeID + "-" + res.ClientID + "-" + res.IssuerUrl)
146+
d.SetId(serviceName + "/" + kubeID)
129147
}
130148
}
131149

ovh/types_iploadbalancing.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (opts *IPLoadbalancingHttpRouteActionOpts) FromResource(d *schema.ResourceD
246246
return opts
247247
}
248248

249-
//IPLoadbalancingHttpRoute HTTP Route
249+
// IPLoadbalancingHttpRoute HTTP Route
250250
type IPLoadbalancingHttpRouteOpts struct {
251251
Action IPLoadbalancingHttpRouteActionOpts `json:"action"` //Action triggered when all rules match
252252
DisplayName *string `json:"displayName,omitempty"` //Human readable name for your route, this field is for you
@@ -291,7 +291,7 @@ func (v IPLoadbalancingHttpRouteAction) ToMap() map[string]interface{} {
291291
return obj
292292
}
293293

294-
//IPLoadbalancingHttpRoute HTTP Route
294+
// IPLoadbalancingHttpRoute HTTP Route
295295
type IPLoadbalancingHttpRoute struct {
296296
Action IPLoadbalancingHttpRouteAction `json:"action"` //Action triggered when all rules match
297297
DisplayName *string `json:"displayName"` //Human readable name for your route, this field is for you
@@ -341,7 +341,7 @@ func (opts *IPLoadbalancingTcpRouteActionOpts) FromResource(d *schema.ResourceDa
341341
return opts
342342
}
343343

344-
//IPLoadbalancingTcpRoute HTTP Route
344+
// IPLoadbalancingTcpRoute HTTP Route
345345
type IPLoadbalancingTcpRouteOpts struct {
346346
Action IPLoadbalancingTcpRouteActionOpts `json:"action"` //Action triggered when all rules match
347347
DisplayName *string `json:"displayName,omitempty"` //Human readable name for your route, this field is for you
@@ -381,7 +381,7 @@ func (v IPLoadbalancingTcpRouteAction) ToMap() map[string]interface{} {
381381
return obj
382382
}
383383

384-
//IPLoadbalancingTcpRoute HTTP Route
384+
// IPLoadbalancingTcpRoute HTTP Route
385385
type IPLoadbalancingTcpRoute struct {
386386
Action IPLoadbalancingTcpRouteAction `json:"action"` //Action triggered when all rules match
387387
DisplayName *string `json:"displayName"` //Human readable name for your route, this field is for you
@@ -419,7 +419,7 @@ func (v IPLoadbalancingTcpRoute) ToMap() map[string]interface{} {
419419
return obj
420420
}
421421

422-
//IPLoadbalancingRouteRule Route Rule
422+
// IPLoadbalancingRouteRule Route Rule
423423
type IPLoadbalancingRouteRule struct {
424424
DisplayName *string `json:"displayName"` //Human readable name for your rule
425425
Field string `json:"field"` //Name of the field to match like "protocol" or "host". See "/ipLoadbalancing/{serviceName}/availableRouteRules" for a list of available rules
@@ -468,7 +468,7 @@ func (v IPLoadbalancingRouteRule) ToMapForRoutes() map[string]interface{} {
468468
return obj
469469
}
470470

471-
//IPLoadbalancingRouteRule Route Rule
471+
// IPLoadbalancingRouteRule Route Rule
472472
type IPLoadbalancingRouteRuleOpts struct {
473473
DisplayName *string `json:"displayName,omitempty"` //Human readable name for your rule
474474
Field string `json:"field"` //Name of the field to match like "protocol" or "host". See "/ipLoadbalancing/{serviceName}/availableRouteRules" for a list of available rules

website/docs/r/cloud_project_kube_oidc.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ The following arguments are supported:
5858
* `oidcSigningAlgs` - Array of signing algorithms accepted. Default is `RS256`.
5959

6060
* `oidcCaContent` - Content of the certificate for the CA, in Base64 format, that signed your identity provider's web certificate. Defaults to the host's root CAs.
61+
62+
## Import
63+
64+
OVHcloud Managed Kubernetes Service cluster OIDC can be imported using the tenant `service_name` and cluster id `kube_id` separated by "/" E.g.,
65+
66+
```bash
67+
$ terraform import ovh_cloud_project_kube_oidc.my-oidc service_name/kube_id
68+
```

0 commit comments

Comments
 (0)