forked from zscaler/terraform-provider-zia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zia_#193_new_app_service_data_sources (zscaler#193)
* (feat) Added application services data source * Added application services AccTest * fixed conflicts
- Loading branch information
Showing
9 changed files
with
297 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package zia | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservicesgroup" | ||
) | ||
|
||
func dataSourceFWApplicationServicesGroupLite() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceFWApplicationServicesGroupLiteRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The unique identifier for the application service.", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The name of the application service.", | ||
}, | ||
"name_l10n_tag": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceFWApplicationServicesGroupLiteRead(d *schema.ResourceData, m interface{}) error { | ||
zClient := m.(*Client) | ||
|
||
var resp *applicationservicesgroup.ApplicationServicesGroupLite | ||
id, ok := getIntFromResourceData(d, "id") | ||
if ok { | ||
log.Printf("[INFO] Getting data for application services group id: %d\n", id) | ||
res, err := zClient.applicationservicesgroup.Get(id) | ||
if err != nil { | ||
return err | ||
} | ||
resp = res | ||
} | ||
name, _ := d.Get("name").(string) | ||
if resp == nil && name != "" { | ||
log.Printf("[INFO] Getting data for application services group: %s\n", name) | ||
res, err := zClient.applicationservicesgroup.GetByName(name) | ||
if err != nil { | ||
return err | ||
} | ||
resp = res | ||
} | ||
|
||
if resp != nil { | ||
d.SetId(fmt.Sprintf("%d", resp.ID)) | ||
_ = d.Set("name", resp.Name) | ||
_ = d.Set("name_l10n_tag", resp.NameL10nTag) | ||
|
||
} else { | ||
return fmt.Errorf("couldn't find any device name '%s' or id '%d'", name, id) | ||
} | ||
|
||
return nil | ||
} |
51 changes: 51 additions & 0 deletions
51
zia/data_source_zia_application_services_group_lite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package zia | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceFWApplicationServicesGroupLite_Basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckDataSourceFWApplicationServicesGroupLiteConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.office365"), | ||
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.zoom"), | ||
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.webex"), | ||
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.ring_central"), | ||
testAccDataSourceFWApplicationServicesGroupLiteCheck("data.zia_firewall_filtering_application_services_group.logmein"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceFWApplicationServicesGroupLiteCheck(name string) resource.TestCheckFunc { | ||
return resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(name, "id"), | ||
resource.TestCheckResourceAttrSet(name, "name"), | ||
) | ||
} | ||
|
||
var testAccCheckDataSourceFWApplicationServicesGroupLiteConfig_basic = ` | ||
data "zia_firewall_filtering_application_services_group" "office365"{ | ||
name = "OFFICE365" | ||
} | ||
data "zia_firewall_filtering_application_services_group" "zoom"{ | ||
name = "ZOOM" | ||
} | ||
data "zia_firewall_filtering_application_services_group" "webex"{ | ||
name = "WEBEX" | ||
} | ||
data "zia_firewall_filtering_application_services_group" "ring_central"{ | ||
name = "RINGCENTRAL" | ||
} | ||
data "zia_firewall_filtering_application_services_group" "logmein"{ | ||
name = "LOGMEIN" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package zia | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/zscaler/zscaler-sdk-go/zia/services/firewallpolicies/applicationservices" | ||
) | ||
|
||
func dataSourceFWApplicationServicesLite() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceFWApplicationServicesLiteRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The unique identifier for the application service.", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The name of the application service.", | ||
}, | ||
"name_l10n_tag": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceFWApplicationServicesLiteRead(d *schema.ResourceData, m interface{}) error { | ||
zClient := m.(*Client) | ||
|
||
var resp *applicationservices.ApplicationServicesLite | ||
id, ok := getIntFromResourceData(d, "id") | ||
if ok { | ||
log.Printf("[INFO] Getting data for application services id: %d\n", id) | ||
res, err := zClient.applicationservices.Get(id) | ||
if err != nil { | ||
return err | ||
} | ||
resp = res | ||
} | ||
name, _ := d.Get("name").(string) | ||
if resp == nil && name != "" { | ||
log.Printf("[INFO] Getting data for admin role name: %s\n", name) | ||
res, err := zClient.applicationservices.GetByName(name) | ||
if err != nil { | ||
return err | ||
} | ||
resp = res | ||
} | ||
|
||
if resp != nil { | ||
d.SetId(fmt.Sprintf("%d", resp.ID)) | ||
_ = d.Set("name", resp.Name) | ||
_ = d.Set("name_l10n_tag", resp.NameL10nTag) | ||
|
||
} else { | ||
return fmt.Errorf("couldn't find any device name '%s' or id '%d'", name, id) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package zia | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceFWApplicationServicesLite_Basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckDataSourceFWApplicationServicesLiteConfig_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.skype_business"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.one_drive"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.exchange_online"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.m365_common"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.zoom_meeting"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_meeting"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_teams"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.webex_calling"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.ring_central_meeting"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.go_to_meeting"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.logmein_meeting"), | ||
testAccDataSourceFWApplicationServicesLiteCheck("data.zia_firewall_filtering_application_services.logmein_rescue"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceFWApplicationServicesLiteCheck(name string) resource.TestCheckFunc { | ||
return resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(name, "id"), | ||
resource.TestCheckResourceAttrSet(name, "name"), | ||
) | ||
} | ||
|
||
var testAccCheckDataSourceFWApplicationServicesLiteConfig_basic = ` | ||
data "zia_firewall_filtering_application_services" "skype_business"{ | ||
name = "SKYPEFORBUSINESS" | ||
} | ||
data "zia_firewall_filtering_application_services" "one_drive"{ | ||
name = "FILE_SHAREPT_ONEDRIVE" | ||
} | ||
data "zia_firewall_filtering_application_services" "exchange_online"{ | ||
name = "EXCHANGEONLINE" | ||
} | ||
data "zia_firewall_filtering_application_services" "m365_common"{ | ||
name = "M365COMMON" | ||
} | ||
data "zia_firewall_filtering_application_services" "zoom_meeting"{ | ||
name = "ZOOMMEETING" | ||
} | ||
data "zia_firewall_filtering_application_services" "webex_meeting"{ | ||
name = "WEBEXMEETING" | ||
} | ||
data "zia_firewall_filtering_application_services" "webex_teams"{ | ||
name = "WEBEXTEAMS" | ||
} | ||
data "zia_firewall_filtering_application_services" "webex_calling"{ | ||
name = "WEBEXCALLING" | ||
} | ||
data "zia_firewall_filtering_application_services" "ring_central_meeting"{ | ||
name = "RINGCENTRALMEETING" | ||
} | ||
data "zia_firewall_filtering_application_services" "go_to_meeting"{ | ||
name = "GOTOMEETING" | ||
} | ||
data "zia_firewall_filtering_application_services" "goto_meeting_inroom"{ | ||
name = "GOTOMEETING_INROOM" | ||
} | ||
data "zia_firewall_filtering_application_services" "logmein_meeting"{ | ||
name = "LOGMEINMEETING" | ||
} | ||
data "zia_firewall_filtering_application_services" "logmein_rescue"{ | ||
name = "LOGMEINRESCUE" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters