/
data_cloud_project_database_integration.go
104 lines (94 loc) · 2.68 KB
/
data_cloud_project_database_integration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package ovh
import (
"context"
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataSourceCloudProjectDatabaseIntegration() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceCloudProjectDatabaseIntegrationRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},
"engine": {
Type: schema.TypeString,
Description: "Name of the engine of the service",
Required: true,
ValidateDiagFunc: validateCloudProjectDatabaseIntegrationEngine,
},
"cluster_id": {
Type: schema.TypeString,
Description: "Cluster ID",
Required: true,
},
"id": {
Type: schema.TypeString,
Description: "Integration ID",
Required: true,
},
//Computed
"destination_service_id": {
Type: schema.TypeString,
Description: "ID of the destination service",
Computed: true,
},
"parameters": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Parameters for the integration",
Computed: true,
},
"source_service_id": {
Type: schema.TypeString,
Description: "ID of the source service",
Computed: true,
},
"status": {
Type: schema.TypeString,
Description: "Current status of the integration",
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Type of the integration",
Computed: true,
},
},
}
}
func dataSourceCloudProjectDatabaseIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
engine := d.Get("engine").(string)
clusterID := d.Get("cluster_id").(string)
id := d.Get("id").(string)
endpoint := fmt.Sprintf("/cloud/project/%s/database/%s/%s/integration/%s",
url.PathEscape(serviceName),
url.PathEscape(engine),
url.PathEscape(clusterID),
url.PathEscape(id),
)
res := &CloudProjectDatabaseIntegrationResponse{}
log.Printf("[DEBUG] Will read acl %s from cluster %s from project %s", id, clusterID, serviceName)
if err := config.OVHClient.GetWithContext(ctx, endpoint, res); err != nil {
return diag.FromErr(helpers.CheckDeleted(d, err, endpoint))
}
for k, v := range res.ToMap() {
if k != "id" {
d.Set(k, v)
} else {
d.SetId(fmt.Sprint(v))
}
}
log.Printf("[DEBUG] Read integration %+v", res)
return nil
}