Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding terraform support #181

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
## 2.7.1
## 2.8.0

FEATURES

* **New Resource:** `checkpoint_management_delete_infinity_idp_object`
* **New Resource:** `checkpoint_management_delete_infinity_idp`
* **New Resource:** `checkpoint_management_mobile_access_section`
* **New Resource:** `checkpoint_management_mobile_access_rule`
* **New Resource:** `checkpoint_management_mobile_access_profile_section`
* **New Resource:** `checkpoint_management_mobile_access_profile_rule`
* **New Resource:** `checkpoint_management_network_probe`
* **New Resource:** `checkpoint_management_override_categorization`
* **New Resource:** `checkpoint_management_interface`
* **New Resource:** `checkpoint_management_resource_smtp`
Expand All @@ -26,6 +32,14 @@ FEATURES
* **New Resource:** `checkpoint_management_data_type_group`
* **New Resource:** `checkpoint_management_data_type_traditional_group`
* **New Resource:** `checkpoint_management_data_type_compound_group`

* **New Data Source:** `checkpoint_management_infinity_idp_object`
* **New Data Source:** `checkpoint_management_infinity_idp`
* **New Data Source:** `checkpoint_management_mobile_access_section`
* **New Data Source:** `checkpoint_management_mobile_access_rule`
* **New Data Source:** `checkpoint_management_mobile_access_profile_section`
* **New Data Source:** `checkpoint_management_mobile_access_profile_rule`
* **New Data Source:** `checkpoint_management_network_probe`
* **New Data Source:** `checkpoint_management_override_categorization`
* **New Data Source:** `checkpoint_management_interface`
* **New Data Source:** `checkpoint_management_resource_smtp`
Expand Down
124 changes: 124 additions & 0 deletions checkpoint/data_source_checkpoint_management_infinity_idp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package checkpoint

import (
"fmt"
checkpoint "github.com/CheckPointSW/cp-mgmt-api-go-sdk/APIFiles"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

func dataSourceManagementInfinityIdp() *schema.Resource {
return &schema.Resource{

Read: dataSourceManagementDeleteInfinityIdpRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Object name.",
},
"uid": {
Type: schema.TypeString,
Optional: true,
Description: "Object unique identifier.",
},
"idp_domains": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of tag identifiers.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"idp_id": {
Type: schema.TypeString,
Computed: true,
Description: "Object unique identifier.",
},
"idp_name": {
Type: schema.TypeString,
Computed: true,
Description: "Object unique identifier.",
},
"idp_type": {
Type: schema.TypeString,
Computed: true,
Description: "Object unique identifier.",
},
"tags": {
Type: schema.TypeSet,
Computed: true,
Description: "Collection of tag identifiers.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
func dataSourceManagementDeleteInfinityIdpRead(d *schema.ResourceData, m interface{}) error {

client := m.(*checkpoint.ApiClient)

name := d.Get("name").(string)
uid := d.Get("uid").(string)

payload := make(map[string]interface{})

if name != "" {
payload["name"] = name
} else if uid != "" {
payload["uid"] = uid
}

showInfinityIdpRes, err := client.ApiCall("show-infinity-idp", payload, client.GetSessionID(), true, client.IsProxyUsed())
if err != nil {
return fmt.Errorf(err.Error())
}
if !showInfinityIdpRes.Success {
return fmt.Errorf(showInfinityIdpRes.ErrorMsg)
}

infinityIdp := showInfinityIdpRes.GetData()

log.Println("Read Infinity-Idp - Show JSON = ", infinityIdp)

if v := infinityIdp["uid"]; v != nil {
_ = d.Set("uid", v)
d.SetId(v.(string))
}

if v := infinityIdp["name"]; v != nil {
_ = d.Set("name", v)
}

if v := infinityIdp["idp-domains"]; v != nil {
_ = d.Set("idp_domains", v.([]interface{}))
}
if v := infinityIdp["idp-id"]; v != nil {
_ = d.Set("idp_id", v)
}
if v := infinityIdp["idp-name"]; v != nil {
_ = d.Set("idp_name", v)
}
if v := infinityIdp["idp-type"]; v != nil {
_ = d.Set("idp_type", v)
}

if infinityIdp["tags"] != nil {
tagsJson := infinityIdp["tags"].([]interface{})
var tagsIds = make([]string, 0)
if len(tagsJson) > 0 {
// Create slice of tag names
for _, tag := range tagsJson {
tag := tag.(map[string]interface{})
tagsIds = append(tagsIds, tag["name"].(string))
}
}
_ = d.Set("tags", tagsIds)
} else {
_ = d.Set("tags", nil)
}

return nil
}
146 changes: 146 additions & 0 deletions checkpoint/data_source_checkpoint_management_infinity_idp_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package checkpoint

import (
"fmt"
checkpoint "github.com/CheckPointSW/cp-mgmt-api-go-sdk/APIFiles"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

func dataSourceManagementInfinityIdpObject() *schema.Resource {
return &schema.Resource{

Read: dataSourceManagementDeleteInfinityIdpObjectRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Object name.",
},
"uid": {
Type: schema.TypeString,
Optional: true,
Description: "Object unique identifier.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description string.",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Entity name in the Management Server.",
},
"ext_id": {
Type: schema.TypeString,
Computed: true,
Description: "Entity unique identifier in the Identity Provider.",
},
"idp_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Identity Provider name in Management Server.",
},
"idp_id": {
Type: schema.TypeString,
Computed: true,
Description: "Object unique identifier.",
},
"idp_name": {
Type: schema.TypeString,
Computed: true,
Description: "Object unique identifier.",
},
"object_type": {
Type: schema.TypeString,
Computed: true,
Description: "Entity type - can be user/group/machine.",
},
"tags": {
Type: schema.TypeSet,
Computed: true,
Description: "Collection of tag identifiers.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}

func dataSourceManagementDeleteInfinityIdpObjectRead(d *schema.ResourceData, m interface{}) error {

client := m.(*checkpoint.ApiClient)

name := d.Get("name").(string)
uid := d.Get("uid").(string)

payload := make(map[string]interface{})

if name != "" {
payload["name"] = name
} else if uid != "" {
payload["uid"] = uid
}

showInfinityIdpRes, err := client.ApiCall("show-infinity-idp-object", payload, client.GetSessionID(), true, client.IsProxyUsed())
if err != nil {
return fmt.Errorf(err.Error())
}
if !showInfinityIdpRes.Success {
return fmt.Errorf(showInfinityIdpRes.ErrorMsg)
}

infinityIdp := showInfinityIdpRes.GetData()

log.Println("Read Infinity-Idp-Object - Show JSON = ", infinityIdp)

if v := infinityIdp["uid"]; v != nil {
_ = d.Set("uid", v)
d.SetId(v.(string))
}

if v := infinityIdp["name"]; v != nil {
_ = d.Set("name", v)
}

if v := infinityIdp["description"]; v != nil {
_ = d.Set("description", v)
}
if v := infinityIdp["display-name"]; v != nil {
_ = d.Set("display_name", v)
}
if v := infinityIdp["ext-id"]; v != nil {
_ = d.Set("ext_id", v)
}
if v := infinityIdp["idp-display-name"]; v != nil {
_ = d.Set("idp_display_name", v)
}
if v := infinityIdp["idp-id"]; v != nil {
_ = d.Set("idp_id", v)
}
if v := infinityIdp["idp-name"]; v != nil {
_ = d.Set("idp_name", v)
}
if v := infinityIdp["object-type"]; v != nil {
_ = d.Set("object_type", v)
}

if infinityIdp["tags"] != nil {
tagsJson := infinityIdp["tags"].([]interface{})
var tagsIds = make([]string, 0)
if len(tagsJson) > 0 {
// Create slice of tag names
for _, tag := range tagsJson {
tag := tag.(map[string]interface{})
tagsIds = append(tagsIds, tag["name"].(string))
}
}
_ = d.Set("tags", tagsIds)
} else {
_ = d.Set("tags", nil)
}

return nil
}
Loading