1
1
package ovh
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"log"
6
7
"net/url"
8
+ "os"
7
9
"regexp"
8
10
"strconv"
11
+ "strings"
9
12
"time"
10
13
11
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -22,9 +25,7 @@ func resourceCloudProjectUser() *schema.Resource {
22
25
Delete : resourceCloudProjectUserDelete ,
23
26
24
27
Importer : & schema.ResourceImporter {
25
- State : func (d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
26
- return []* schema.ResourceData {d }, nil
27
- },
28
+ StateContext : resourceCloudProjectUserImportState ,
28
29
},
29
30
30
31
Schema : map [string ]* schema.Schema {
@@ -105,6 +106,27 @@ func resourceCloudProjectUser() *schema.Resource {
105
106
}
106
107
}
107
108
109
+ func resourceCloudProjectUserImportState (ctx context.Context , d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
110
+ userId := d .Id ()
111
+ // Fallback to the environment variable if service_name not given
112
+ serviceName := os .Getenv ("OVH_CLOUD_PROJECT_SERVICE" )
113
+
114
+ splitId := strings .SplitN (userId , "/" , 2 )
115
+ if len (splitId ) == 2 {
116
+ serviceName = splitId [0 ]
117
+ userId = splitId [1 ]
118
+ }
119
+
120
+ if serviceName == "" || userId == "" {
121
+ return nil , fmt .Errorf ("Import Id is not service_name/id formatted" )
122
+ }
123
+
124
+ d .SetId (userId )
125
+ d .Set ("service_name" , serviceName )
126
+
127
+ return []* schema.ResourceData {d }, nil
128
+ }
129
+
108
130
func validateCloudProjectUserRoleFunc (v interface {}, k string ) (ws []string , errors []error ) {
109
131
err := helpers .ValidateStringEnum (v .(string ), []string {
110
132
"administrator" ,
0 commit comments