@@ -6,20 +6,32 @@ import (
6
6
"net/url"
7
7
8
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
- "github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
10
-
11
9
"github.com/ovh/go-ovh/ovh"
10
+ "github.com/ovh/terraform-provider-ovh/ovh/helpers"
11
+ "github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
12
12
)
13
13
14
14
func dataSourceCloudRegion () * schema.Resource {
15
15
return & schema.Resource {
16
16
Read : dataSourceCloudRegionRead ,
17
17
Schema : map [string ]* schema.Schema {
18
18
"project_id" : {
19
- Type : schema .TypeString ,
20
- Required : true ,
21
- ForceNew : true ,
22
- DefaultFunc : schema .EnvDefaultFunc ("OVH_PROJECT_ID" , nil ),
19
+ Type : schema .TypeString ,
20
+ Optional : true ,
21
+ Computed : true ,
22
+ ForceNew : true ,
23
+ DefaultFunc : schema .EnvDefaultFunc ("OVH_PROJECT_ID" , nil ),
24
+ Description : "Id of the cloud project. DEPRECATED, use `service_name` instead" ,
25
+ ConflictsWith : []string {"service_name" },
26
+ },
27
+ "service_name" : {
28
+ Type : schema .TypeString ,
29
+ Optional : true ,
30
+ Computed : true ,
31
+ ForceNew : true ,
32
+ DefaultFunc : schema .EnvDefaultFunc ("OVH_CLOUD_PROJECT_SERVICE" , nil ),
33
+ Description : "Service name of the resource representing the id of the cloud project." ,
34
+ ConflictsWith : []string {"project_id" },
23
35
},
24
36
"name" : {
25
37
Type : schema .TypeString ,
@@ -70,12 +82,16 @@ func dataSourceCloudRegion() *schema.Resource {
70
82
71
83
func dataSourceCloudRegionRead (d * schema.ResourceData , meta interface {}) error {
72
84
config := meta .(* Config )
73
- projectId := d .Get ("project_id" ).(string )
85
+ serviceName , err := helpers .GetCloudProjectServiceName (d )
86
+ if err != nil {
87
+ return err
88
+ }
89
+
74
90
name := d .Get ("name" ).(string )
75
91
76
- log .Printf ("[DEBUG] Will read public cloud region %s for project: %s" , name , projectId )
92
+ log .Printf ("[DEBUG] Will read public cloud region %s for project: %s" , name , serviceName )
77
93
78
- region , err := getCloudRegion (projectId , name , config .OVHClient )
94
+ region , err := getCloudRegion (serviceName , name , config .OVHClient )
79
95
if err != nil {
80
96
return err
81
97
}
@@ -98,18 +114,20 @@ func dataSourceCloudRegionRead(d *schema.ResourceData, meta interface{}) error {
98
114
}
99
115
100
116
d .Set ("services" , services )
101
- d .SetId (fmt .Sprintf ("%s_%s" , projectId , name ))
117
+ d .Set ("service_name" , serviceName )
118
+ d .Set ("project_id" , serviceName )
119
+ d .SetId (fmt .Sprintf ("%s_%s" , serviceName , name ))
102
120
103
121
return nil
104
122
}
105
123
106
- func getCloudRegion (projectId , region string , client * ovh.Client ) (* CloudRegionResponse , error ) {
107
- log .Printf ("[DEBUG] Will read public cloud region %s for project: %s" , region , projectId )
124
+ func getCloudRegion (serviceName , region string , client * ovh.Client ) (* CloudRegionResponse , error ) {
125
+ log .Printf ("[DEBUG] Will read public cloud region %s for project: %s" , region , serviceName )
108
126
109
127
response := & CloudRegionResponse {}
110
128
endpoint := fmt .Sprintf (
111
129
"/cloud/project/%s/region/%s" ,
112
- url .PathEscape (projectId ),
130
+ url .PathEscape (serviceName ),
113
131
url .PathEscape (region ),
114
132
)
115
133
err := client .Get (endpoint , response )
0 commit comments