Skip to content

Commit 7a80d82

Browse files
committed
Add resources for on-boarding
1 parent 11a1e38 commit 7a80d82

20 files changed

+1760
-77
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package checkpoint
2+
3+
import (
4+
"fmt"
5+
checkpoint "github.com/CheckPointSW/cp-mgmt-api-go-sdk/APIFiles"
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"log"
9+
)
10+
11+
func dataSourceManagementCloudServices() *schema.Resource {
12+
return &schema.Resource{
13+
Read: dataSourceManagementCloudServicesRead,
14+
Schema: map[string]*schema.Schema{
15+
"status": {
16+
Type: schema.TypeString,
17+
Computed: true,
18+
Description: "Status of the connection to the Infinity Portal.",
19+
},
20+
"connected_at": {
21+
Type: schema.TypeMap,
22+
Computed: true,
23+
Description: "The time of the connection between the Management Server and the Infinity Portal.",
24+
Elem: &schema.Resource{
25+
Schema: map[string]*schema.Schema{
26+
"iso_8601": {
27+
Type: schema.TypeString,
28+
Computed: true,
29+
Description: "Date and time represented in international ISO 8601 format.",
30+
},
31+
"posix": {
32+
Type: schema.TypeInt,
33+
Computed: true,
34+
Description: "Number of milliseconds that have elapsed since 00:00:00, 1 January 1970.",
35+
},
36+
},
37+
},
38+
},
39+
"management_url": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
Description: "The Management Server's public URL.",
43+
},
44+
},
45+
}
46+
}
47+
48+
func dataSourceManagementCloudServicesRead(d *schema.ResourceData, m interface{}) error {
49+
client := m.(*checkpoint.ApiClient)
50+
51+
showCloudServices, err := client.ApiCall("show-cloud-services", make(map[string]interface{}), client.GetSessionID(), true, client.IsProxyUsed())
52+
if err != nil {
53+
return fmt.Errorf(err.Error())
54+
}
55+
if !showCloudServices.Success {
56+
return fmt.Errorf(showCloudServices.ErrorMsg)
57+
}
58+
59+
showCloudServicesRes := showCloudServices.GetData()
60+
61+
log.Println("Show Cloud Services - JSON = ", showCloudServicesRes)
62+
63+
if v := showCloudServicesRes["status"]; v != nil {
64+
_ = d.Set("status", v)
65+
}else{
66+
_ = d.Set("status", nil)
67+
}
68+
69+
if v := showCloudServicesRes["connected-at"]; v != nil {
70+
connectedAtShow := showCloudServicesRes["connected-at"].(map[string]interface{})
71+
connectedAtState := make(map[string]interface{})
72+
if v := connectedAtShow["iso-8601"]; v != nil {
73+
connectedAtState["iso_8601"] = v
74+
}
75+
if v := connectedAtShow["posix"]; v != nil {
76+
connectedAtState["posix"] = v
77+
}
78+
_ = d.Set("connected_at", connectedAtState)
79+
}else{
80+
_ = d.Set("connected_at", nil)
81+
}
82+
83+
if v := showCloudServicesRes["management-url"]; v != nil {
84+
_ = d.Set("management_url", v)
85+
}else{
86+
_ = d.Set("management_url", nil)
87+
}
88+
89+
d.SetId("show-cloud-services-" + acctest.RandString(5))
90+
91+
return nil
92+
}

checkpoint/data_source_checkpoint_management_package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func dataSourceManagementPackageRead(d *schema.ResourceData, m interface{}) erro
140140
}
141141
}
142142
_, installationTargetsInConf := d.GetOk("installation_targets")
143-
if installationTargetsIds[0] == "all" && !installationTargetsInConf {
143+
if len(installationTargetsIds) == 1 && installationTargetsIds[0] == "all" && !installationTargetsInConf {
144144
_ = d.Set("installation_targets", []interface{}{})
145145
} else {
146146
_ = d.Set("installation_targets", installationTargetsIds)

checkpoint/data_source_checkpoint_management_repository_package.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ func dataSourceManagementRepositoryPackageRead(d *schema.ResourceData, m interfa
4949
if v := RepositoryPackage["uid"]; v != nil {
5050
_ = d.Set("uid", v)
5151
d.SetId(v.(string))
52-
} else {
53-
d.SetId("ff")
5452
}
5553

5654
if v, ok := d.GetOk("name"); ok {

checkpoint/data_source_checkpoint_management_vpn_community_meshed.go

Lines changed: 223 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func dataSourceManagementVpnCommunityMeshed() *schema.Resource {
6161
Computed: true,
6262
Description: "The encryption algorithm to be used.",
6363
},
64+
"ike_p1_rekey_time": {
65+
Type: schema.TypeInt,
66+
Computed: true,
67+
Description: "Indicates the time interval for IKE phase 1 renegotiation.",
68+
},
6469
},
6570
},
6671
},
@@ -80,6 +85,21 @@ func dataSourceManagementVpnCommunityMeshed() *schema.Resource {
8085
Computed: true,
8186
Description: "The encryption algorithm to be used.",
8287
},
88+
"ike_p2_use_pfs": {
89+
Type: schema.TypeBool,
90+
Computed: true,
91+
Description: "Indicates whether Perfect Forward Secrecy (PFS) is being used for IKE phase 2.",
92+
},
93+
"ike_p2_pfs_dh_grp": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "The Diffie-Hellman group to be used.",
97+
},
98+
"ike_p2_rekey_time": {
99+
Type: schema.TypeInt,
100+
Computed: true,
101+
Description: "Indicates the time interval for IKE phase 2 renegotiation.",
102+
},
83103
},
84104
},
85105
},
@@ -121,6 +141,104 @@ func dataSourceManagementVpnCommunityMeshed() *schema.Resource {
121141
},
122142
},
123143
},
144+
"tunnel_granularity": {
145+
Type: schema.TypeString,
146+
Computed: true,
147+
Description: "VPN tunnel sharing option to be used.",
148+
},
149+
"granular_encryptions": {
150+
Type: schema.TypeList,
151+
Computed: true,
152+
Description: "VPN granular encryption settings.",
153+
Elem: &schema.Resource{
154+
Schema: map[string]*schema.Schema{
155+
"internal_gateway": {
156+
Type: schema.TypeString,
157+
Computed: true,
158+
Description: "Internally managed Check Point gateway identified by name or UID, or 'Any' for all internal-gateways participants in this community.",
159+
},
160+
"external_gateway": {
161+
Type: schema.TypeString,
162+
Computed: true,
163+
Description: "Externally managed or 3rd party gateway identified by name or UID.",
164+
},
165+
"encryption_method": {
166+
Type: schema.TypeString,
167+
Computed: true,
168+
Description: "The encryption method to be used.",
169+
},
170+
"encryption_suite": {
171+
Type: schema.TypeString,
172+
Computed: true,
173+
Description: "The encryption suite to be used.",
174+
},
175+
"ike_phase_1": {
176+
Type: schema.TypeMap,
177+
Computed: true,
178+
Description: "Ike Phase 1 settings. Only applicable when the encryption-suite is set to [custom].",
179+
Elem: &schema.Resource{
180+
Schema: map[string]*schema.Schema{
181+
"data_integrity": {
182+
Type: schema.TypeString,
183+
Computed: true,
184+
Description: "The hash algorithm to be used.",
185+
},
186+
"diffie_hellman_group": {
187+
Type: schema.TypeString,
188+
Computed: true,
189+
Description: "The Diffie-Hellman group to be used.",
190+
},
191+
"encryption_algorithm": {
192+
Type: schema.TypeString,
193+
Computed: true,
194+
Description: "The encryption algorithm to be used.",
195+
},
196+
"ike_p1_rekey_time": {
197+
Type: schema.TypeInt,
198+
Computed: true,
199+
Description: "Indicates the time interval for IKE phase 1 renegotiation.",
200+
},
201+
},
202+
},
203+
},
204+
"ike_phase_2": {
205+
Type: schema.TypeMap,
206+
Computed: true,
207+
Description: "Ike Phase 2 settings. Only applicable when the encryption-suite is set to [custom].",
208+
Elem: &schema.Resource{
209+
Schema: map[string]*schema.Schema{
210+
"data_integrity": {
211+
Type: schema.TypeString,
212+
Computed: true,
213+
Description: "The hash algorithm to be used.",
214+
Default: "sha1",
215+
},
216+
"encryption_algorithm": {
217+
Type: schema.TypeString,
218+
Computed: true,
219+
Description: "The encryption algorithm to be used.",
220+
},
221+
"ike_p2_use_pfs": {
222+
Type: schema.TypeBool,
223+
Computed: true,
224+
Description: "Indicates whether Perfect Forward Secrecy (PFS) is being used for IKE phase 2.",
225+
},
226+
"ike_p2_pfs_dh_grp": {
227+
Type: schema.TypeString,
228+
Computed: true,
229+
Description: "The Diffie-Hellman group to be used.",
230+
},
231+
"ike_p2_rekey_time": {
232+
Type: schema.TypeInt,
233+
Computed: true,
234+
Description: "Indicates the time interval for IKE phase 2 renegotiation.",
235+
},
236+
},
237+
},
238+
},
239+
},
240+
},
241+
},
124242
"tags": {
125243
Type: schema.TypeSet,
126244
Computed: true,
@@ -223,7 +341,9 @@ func dataSourceManagementVpnCommunityMeshedRead(d *schema.ResourceData, m interf
223341
if v, _ := ikePhase1Map["encryption-algorithm"]; v != nil {
224342
ikePhase1MapToReturn["encryption_algorithm"] = v
225343
}
226-
344+
if v := ikePhase1Map["ike-p1-rekey-time"]; v != nil {
345+
ikePhase1MapToReturn["ike_p1_rekey_time"] = v
346+
}
227347
_, ikePhase1InConf := d.GetOk("ike_phase_1")
228348
defaultIkePhase1 := map[string]interface{}{"encryption_algorithm": "aes-256", "diffie_hellman_group": "group-2", "data_integrity": "sha1"}
229349
if reflect.DeepEqual(defaultIkePhase1, ikePhase1MapToReturn) && !ikePhase1InConf {
@@ -248,7 +368,15 @@ func dataSourceManagementVpnCommunityMeshedRead(d *schema.ResourceData, m interf
248368
if v, _ := ikePhase2Map["encryption-algorithm"]; v != nil {
249369
ikePhase2MapToReturn["encryption_algorithm"] = v
250370
}
251-
371+
if v := ikePhase2Map["ike-p2-use-pfs"]; v != nil {
372+
ikePhase2MapToReturn["ike_p2_use_pfs"] = v
373+
}
374+
if v := ikePhase2Map["ike-p2-pfs-dh-grp"]; v != nil {
375+
ikePhase2MapToReturn["ike_p2_pfs_dh_grp"] = v
376+
}
377+
if v := ikePhase2Map["ike-p2-rekey-time"]; v != nil {
378+
ikePhase2MapToReturn["ike_p2_rekey_time"] = v
379+
}
252380
_, ikePhase2InConf := d.GetOk("ike_phase_2")
253381
defaultIkePhase2 := map[string]interface{}{"encryption_algorithm": "aes-128", "data_integrity": "sha1"}
254382
if reflect.DeepEqual(defaultIkePhase2, ikePhase2MapToReturn) && !ikePhase2InConf {
@@ -317,6 +445,99 @@ func dataSourceManagementVpnCommunityMeshedRead(d *schema.ResourceData, m interf
317445
}
318446
}
319447

448+
if v := vpnCommunityMeshed["tunnel-granularity"]; v != nil {
449+
_ = d.Set("tunnel_granularity", v)
450+
}
451+
452+
if vpnCommunityMeshed["granular-encryptions"] != nil {
453+
granularEncryptions, ok := vpnCommunityMeshed["granular-encryptions"].([]interface{})
454+
if ok {
455+
if len(granularEncryptions) > 0 {
456+
var granularEncryptionsState []map[string]interface{}
457+
for i := range granularEncryptions {
458+
granularEncryptionShow := granularEncryptions[i].(map[string]interface{})
459+
granularEncryptionState := make(map[string]interface{})
460+
if granularEncryptionShow["internal-gateway"] != nil {
461+
var internalGatewayName string
462+
v := granularEncryptionShow["internal-gateway"]
463+
if obj, ok := v.(map[string]interface{}); ok {
464+
if obj["name"] != nil {
465+
internalGatewayName = obj["name"].(string)
466+
}
467+
}else if val, ok := v.(string); ok {
468+
internalGatewayName = val
469+
}
470+
granularEncryptionState["internal_gateway"] = internalGatewayName
471+
}
472+
473+
if granularEncryptionShow["external-gateway"] != nil {
474+
var externalGatewayName string
475+
v := granularEncryptionShow["external-gateway"]
476+
if obj, ok := v.(map[string]interface{}); ok {
477+
if obj["name"] != nil {
478+
externalGatewayName = obj["name"].(string)
479+
}
480+
}else if val, ok := v.(string); ok {
481+
externalGatewayName = val
482+
}
483+
granularEncryptionState["external_gateway"] = externalGatewayName
484+
}
485+
486+
if v := granularEncryptionShow["encryption-method"]; v != nil {
487+
granularEncryptionState["encryption_method"] = v
488+
}
489+
490+
if v := granularEncryptionShow["encryption-suite"]; v != nil {
491+
granularEncryptionState["encryption_suite"] = v
492+
}
493+
494+
if v := granularEncryptionShow["ike-phase-1"]; v != nil {
495+
ikePhase1Show := v.(map[string]interface{})
496+
ikePhase1State := make(map[string]interface{})
497+
if v := ikePhase1Show["encryption-algorithm"]; v != nil {
498+
ikePhase1State["encryption_algorithm"] = v
499+
}
500+
if v := ikePhase1Show["data-integrity"]; v != nil {
501+
ikePhase1State["data_integrity"] = v
502+
}
503+
if v := ikePhase1Show["diffie-hellman-group"]; v != nil {
504+
ikePhase1State["diffie_hellman_group"] = v
505+
}
506+
if v := ikePhase1Show["ike-p1-rekey-time"]; v != nil {
507+
ikePhase1State["ike_p1_rekey_time"] = v
508+
}
509+
granularEncryptionState["ike_phase_1"] = ikePhase1State
510+
}
511+
512+
if v := granularEncryptionShow["ike-phase-2"]; v != nil {
513+
ikePhase2Show := v.(map[string]interface{})
514+
ikePhase2State := make(map[string]interface{})
515+
if v := ikePhase2Show["encryption-algorithm"]; v != nil {
516+
ikePhase2State["encryption_algorithm"] = v
517+
}
518+
if v := ikePhase2Show["data-integrity"]; v != nil {
519+
ikePhase2State["data_integrity"] = v
520+
}
521+
if v := ikePhase2Show["ike-p2-use-pfs"]; v != nil {
522+
ikePhase2State["ike_p2_use_pfs"] = v
523+
}
524+
if v := ikePhase2Show["ike-p2-pfs-dh-grp"]; v != nil {
525+
ikePhase2State["ike_p2_pfs_dh_grp"] = v
526+
}
527+
if v := ikePhase2Show["ike-p2-rekey-time"]; v != nil {
528+
ikePhase2State["ike_p2_rekey_time"] = v
529+
}
530+
granularEncryptionState["ike_phase_2"] = ikePhase2State
531+
}
532+
granularEncryptionsState = append(granularEncryptionsState, granularEncryptionState)
533+
}
534+
_ = d.Set("granular_encryptions", granularEncryptionsState)
535+
}else{
536+
_ = d.Set("granular_encryptions", nil)
537+
}
538+
}
539+
}
540+
320541
if vpnCommunityMeshed["tags"] != nil {
321542
tagsJson, ok := vpnCommunityMeshed["tags"].([]interface{})
322543
if ok {

0 commit comments

Comments
 (0)