Skip to content

Commit

Permalink
Merge pull request #134 from zscaler/zpa-134-fix-implement-skip-blocks
Browse files Browse the repository at this point in the history
fix: Condition to exclude zpa applications block
  • Loading branch information
willguibr authored Oct 3, 2023
2 parents 86d09a4 + cdb7514 commit b75f0e1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.3.2 (October 3, 2023)

### Notes

- Release date: **(October 3, 2023)**
- Supported Terraform version: **v1.x.x**

### Bug Fixes

- [PR #134](https://github.com/zscaler/zscaler-terraformer/pull/134) Implement condition to exclude ``applications`` block from the ZPA resources `zpa_segment_group` and `zpa_server_group`.

## 0.3.1 (August 25, 2023)

### Notes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Usage:

Available Commands:
completion Generate the autocompletion script for the specified shell
generate Fetch resources from the Cloudflare API and generate the respective Terraform stanzas
generate Fetch resources from the ZPA and ZIA API and generate the respective Terraform stanzas
help Help about any command
import Output `terraform import` compatible commands in order to import resources into state
version Print the version number of zscaler-terraformer
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/zscaler/zscaler-terraformer

go 1.19
go 1.20

require (
github.com/dnaeon/go-vcr v1.2.0
Expand All @@ -15,7 +15,7 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/zclconf/go-cty v1.14.0
github.com/zscaler/zscaler-sdk-go/v2 v2.1.1
github.com/zscaler/zscaler-sdk-go/v2 v2.1.2
)

require (
Expand Down Expand Up @@ -54,6 +54,6 @@ require (
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc=
github.com/zclconf/go-cty v1.14.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zscaler/zscaler-sdk-go/v2 v2.1.1 h1:7PpU0fLUCJIx8R8ZIMnjwrWBrQPG6mtm2wdyRgmSlEE=
github.com/zscaler/zscaler-sdk-go/v2 v2.1.1/go.mod h1:PQscsdJVbmOXn7xqkRz3MdwYrt2UGHg37ZlON77iptg=
github.com/zscaler/zscaler-sdk-go/v2 v2.1.2 h1:b5/Z9qxYFZuI8cBhZ2Co+DdfwVLmuY0t0gJR4rONkbI=
github.com/zscaler/zscaler-sdk-go/v2 v2.1.2/go.mod h1:PQscsdJVbmOXn7xqkRz3MdwYrt2UGHg37ZlON77iptg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down Expand Up @@ -591,9 +591,8 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 2 additions & 0 deletions internal/app/zscaler-terraformer/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func generate(cmd *cobra.Command, writer io.Writer, resourceType string) {
if i.Name == "Zscaler Deception" {
continue
}
i.Applications = nil // Suppress the applications block
jsonPayload = append(jsonPayload, i)
}
resourceCount = len(jsonPayload)
Expand All @@ -353,6 +354,7 @@ func generate(cmd *cobra.Command, writer io.Writer, resourceType string) {
if i.Name == "Zscaler Deception" {
continue
}
i.Applications = nil // Suppress the applications block
jsonPayload = append(jsonPayload, i)
}
resourceCount = len(jsonPayload)
Expand Down
4 changes: 2 additions & 2 deletions internal/app/zscaler-terraformer/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlcategories"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlfilteringpolicies"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/user_authentication_settings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zpa"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorcontroller"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorgroup"
Expand Down Expand Up @@ -269,7 +269,6 @@ func createClientMock(r http.RoundTripper, resourceType, zpaClientID, zpaClientS
timewindow: timewindow.New(ziaClient),
urlcategories: urlcategories.New(ziaClient),
urlfilteringpolicies: urlfilteringpolicies.New(ziaClient),
usermanagement: usermanagement.New(ziaClient),
virtualipaddresslist: virtualipaddresslist.New(ziaClient),
vpncredentials: vpncredentials.New(ziaClient),
gretunnels: gretunnels.New(ziaClient),
Expand All @@ -286,6 +285,7 @@ func createClientMock(r http.RoundTripper, resourceType, zpaClientID, zpaClientS
rule_labels: rule_labels.New(ziaClient),
security_policy_settings: security_policy_settings.New(ziaClient),
user_authentication_settings: user_authentication_settings.New(ziaClient),
usermanagement: usermanagement.New(ziaClient),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/zscaler-terraformer/cmd/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlcategories"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlfilteringpolicies"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/user_authentication_settings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zpa"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorcontroller"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorgroup"
Expand Down
7 changes: 6 additions & 1 deletion internal/app/zscaler-terraformer/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlcategories"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/urlfilteringpolicies"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/user_authentication_settings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/usermanagement/usermanagement"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorcontroller"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/appconnectorgroup"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/applicationsegment"
Expand Down Expand Up @@ -321,6 +321,11 @@ func nestBlocks(resourceType string, schemaBlock *tfjson.SchemaBlock, structData

for _, block := range sortedNestedBlocks {
apiBlock := mapTfFieldNameToApi(resourceType, block)

// Skip 'applications' block for 'zpa_segment_group' resource
if (resourceType == "zpa_segment_group" || resourceType == "zpa_server_group") && block == "applications" {
continue // This skips the current iteration of the loop
}
// special cases mapping
if resourceType == "zia_admin_users" && block == "admin_scope" {
output += "admin_scope {\n"
Expand Down

0 comments on commit b75f0e1

Please sign in to comment.