Skip to content

Commit 3c70642

Browse files
authored
Merge pull request #638 from an0rak-dev/expose_gateway_external_infos
Expose gateway's external information and interfaces
2 parents 41f214a + d5b39ee commit 3c70642

4 files changed

+115
-10
lines changed

ovh/resource_cloud_project_gateway.go

+88-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,68 @@ func resourceCloudProjectGateway() *schema.Resource {
7474
Type: schema.TypeString,
7575
Computed: true,
7676
},
77+
"external_information": {
78+
Type: schema.TypeList,
79+
Computed: true,
80+
Description: "External information of the gateway",
81+
Elem: &schema.Resource{
82+
Schema: map[string]*schema.Schema{
83+
"network_id": {
84+
Type: schema.TypeString,
85+
Description: "External network ID of the gateway",
86+
Computed: true,
87+
},
88+
"ips": {
89+
Type: schema.TypeList,
90+
Description: "List of external ips of the gateway",
91+
Computed: true,
92+
Elem: &schema.Resource{
93+
Schema: map[string]*schema.Schema{
94+
"ip": {
95+
Type: schema.TypeString,
96+
Description: "External IP of the gateway",
97+
Computed: true,
98+
},
99+
"subnet_id": {
100+
Type: schema.TypeString,
101+
Description: "Subnet ID of the ip",
102+
Computed: true,
103+
},
104+
},
105+
},
106+
},
107+
},
108+
},
109+
},
110+
"interfaces": {
111+
Type: schema.TypeList,
112+
Computed: true,
113+
Description: "Interfaces list of the gateway",
114+
Elem: &schema.Resource{
115+
Schema: map[string]*schema.Schema{
116+
"id": {
117+
Type: schema.TypeString,
118+
Description: "ID of the interface",
119+
Computed: true,
120+
},
121+
"ip": {
122+
Type: schema.TypeString,
123+
Description: "IP of the interface",
124+
Computed: true,
125+
},
126+
"network_id": {
127+
Type: schema.TypeString,
128+
Description: "Network ID of the interface",
129+
Computed: true,
130+
},
131+
"subnet_id": {
132+
Type: schema.TypeString,
133+
Description: "Subnet ID of the interface",
134+
Computed: true,
135+
},
136+
},
137+
},
138+
},
77139
},
78140
}
79141
}
@@ -163,7 +225,32 @@ func resourceCloudProjectGatewayRead(d *schema.ResourceData, meta interface{}) e
163225
d.SetId(r.Id)
164226
d.Set("service_name", serviceName)
165227

166-
// TODO : add response fields "externalInformation" and "interfaces"
228+
externalInfos := make([]map[string]interface{}, 0)
229+
if r.ExternalInformation != nil {
230+
externalInfo := make(map[string]interface{})
231+
ips := make([]map[string]interface{}, 0)
232+
for _, externalIp := range r.ExternalInformation.Ips {
233+
ip := make(map[string]interface{})
234+
ip["ip"] = externalIp.Ip
235+
ip["subnet_id"] = externalIp.SubnetId
236+
ips = append(ips, ip)
237+
}
238+
externalInfo["ips"] = ips
239+
externalInfo["network_id"] = r.ExternalInformation.NetworkId
240+
externalInfos = append(externalInfos, externalInfo)
241+
}
242+
d.Set("external_information", externalInfos)
243+
244+
interfaces := make([]map[string]string, 0)
245+
for _, responseInterface := range r.Interfaces {
246+
itf := make(map[string]string)
247+
itf["id"] = responseInterface.Id
248+
itf["ip"] = responseInterface.Ip
249+
itf["subnet_id"] = responseInterface.SubnetId
250+
itf["network_id"] = responseInterface.NetworkId
251+
interfaces = append(interfaces, itf)
252+
}
253+
d.Set("interfaces", interfaces)
167254

168255
log.Printf("[DEBUG] Read Public Cloud Gateway %+v", r)
169256
return nil

ovh/resource_cloud_project_gateway_test.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestAccCloudProjectGateway(t *testing.T) {
5252
gatewayName := acctest.RandomWithPrefix(test_prefix)
5353
vlanId := acctest.RandIntRange(100, 200)
5454
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
55+
resourcePath := "ovh_cloud_project_gateway.gateway"
5556

5657
config := fmt.Sprintf(
5758
testAccCloudProjectGatewayConfig,
@@ -76,13 +77,20 @@ func TestAccCloudProjectGateway(t *testing.T) {
7677
{
7778
Config: config,
7879
Check: resource.ComposeTestCheckFunc(
79-
resource.TestCheckResourceAttrSet("ovh_cloud_project_gateway.gateway", "service_name"),
80-
resource.TestCheckResourceAttrSet("ovh_cloud_project_gateway.gateway", "network_id"),
81-
resource.TestCheckResourceAttrSet("ovh_cloud_project_gateway.gateway", "subnet_id"),
82-
resource.TestCheckResourceAttrSet("ovh_cloud_project_gateway.gateway", "model"),
83-
resource.TestCheckResourceAttr("ovh_cloud_project_gateway.gateway", "region", region),
84-
resource.TestCheckResourceAttr("ovh_cloud_project_gateway.gateway", "name", gatewayName),
85-
resource.TestCheckResourceAttr("ovh_cloud_project_gateway.gateway", "model", "s"),
80+
resource.TestCheckResourceAttrSet(resourcePath, "service_name"),
81+
resource.TestCheckResourceAttrSet(resourcePath, "network_id"),
82+
resource.TestCheckResourceAttrSet(resourcePath, "subnet_id"),
83+
resource.TestCheckResourceAttrSet(resourcePath, "model"),
84+
resource.TestCheckResourceAttrSet(resourcePath, "external_information.0.network_id"),
85+
resource.TestCheckResourceAttrSet(resourcePath, "external_information.0.ips.0.ip"),
86+
resource.TestCheckResourceAttrSet(resourcePath, "external_information.0.ips.0.subnet_id"),
87+
resource.TestCheckResourceAttrSet(resourcePath, "interfaces.0.id"),
88+
resource.TestCheckResourceAttrSet(resourcePath, "interfaces.0.ip"),
89+
resource.TestCheckResourceAttrSet(resourcePath, "interfaces.0.subnet_id"),
90+
resource.TestCheckResourceAttrSet(resourcePath, "interfaces.0.network_id"),
91+
resource.TestCheckResourceAttr(resourcePath, "region", region),
92+
resource.TestCheckResourceAttr(resourcePath, "name", gatewayName),
93+
resource.TestCheckResourceAttr(resourcePath, "model", "s"),
8694
),
8795
},
8896
},

ovh/types_cloud.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type CloudProjectGatewayExternalIp struct {
3535
}
3636

3737
type CloudProjectGatewayExternal struct {
38-
Ips []*CloudProjectGatewayExternalIp `json:"ip"`
38+
Ips []*CloudProjectGatewayExternalIp `json:"ips"`
3939
NetworkId string `json:"networkId"`
4040
}
4141

website/docs/r/cloud_project_gateway.html.markdown

+11-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ The following attributes are exported:
5858
* `model` - See Argument Reference above.
5959
* `network_id` - See Argument Reference above.
6060
* `subnet_id` - See Argument Reference above.
61+
* `external_information` - List of External Information of the gateway.
62+
* `network_id` - External network ID of the gateway.
63+
* `ips` - List of external ips of the gateway.
64+
* `ip` - External IP of the gateway.
65+
* `subnet_id` - Subnet ID of the ip.
66+
* `interfaces` - Interfaces list of the gateway.
67+
* `id` - ID of the interface.
68+
* `ip` - IP of the interface.
69+
* `network_id` - Network ID of the interface.
70+
* `subnet_id` - Subnet ID of the interface.
6171
* `status` - Status of the gateway.
6272

6373
## Import
@@ -66,4 +76,4 @@ A gateway can be imported using the `service_name`, `region` and `id` (identifie
6676

6777
```bash
6878
$ terraform import ovh_cloud_project_gateway.gateway service_name/region/id
69-
```
79+
```

0 commit comments

Comments
 (0)