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

fix: Fixed ZIA Issues During Import #257

Merged
merged 1 commit into from
Jan 31, 2025
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 2.0.1 (January, 31 2025)

### Notes

- Release date: **(January, 31 2025)**
- Supported Terraform version: **v1.x.x**

### Bug Fixes
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resource for `zia_dlp_notification_templates` due to heredoc missformatting. - [Issue #253](https://github.com/zscaler/zscaler-terraformer/issues/253)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resource for `zia_end_user_notification` due to heredoc missformatting and attribute validation issue. - [Issue #254](https://github.com/zscaler/zscaler-terraformer/issues/254)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resources for: `zia_forwarding_control_rule` due to missing attribute `id` within the `zpa_gateway` block. - [Issue #255](https://github.com/zscaler/zscaler-terraformer/issues/255)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resources for: `zia_forwarding_control_zpa_gateway` due to missing attribute `type`. - [Issue #256](https://github.com/zscaler/zscaler-terraformer/issues/256)

## 2.0.0 (January, 29 2025) - BREAKING CHANGES

### Notes
Expand Down
48 changes: 23 additions & 25 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,6 @@ func generate(ctx context.Context, cmd *cobra.Command, writer io.Writer, resourc
if api.ZIAService == nil {
log.Fatal("ZIA service is not initialized")
}
// EXACTLY like the TF pattern:
service := api.ZIAService
gws, err := zpa_gateways.GetAll(ctx, service)
if err != nil {
Expand All @@ -1371,6 +1370,8 @@ func generate(ctx context.Context, cmd *cobra.Command, writer io.Writer, resourc
if helpers.IsInList(gw.Name, []string{"Auto ZPA Gateway"}) {
continue
}
// Ensure type is always "ZPA"
gw.Type = "ZPA"
gwsFiltered = append(gwsFiltered, gw)
}
resourceCount = len(gwsFiltered)
Expand Down Expand Up @@ -1471,21 +1472,6 @@ func generate(ctx context.Context, cmd *cobra.Command, writer io.Writer, resourc
m, _ := json.Marshal(rulesFiltered)
_ = json.Unmarshal(m, &jsonStructData)

// case "zia_advanced_settings":
// if api.ZIAService == nil {
// log.Fatal("ZIA service is not initialized")
// }
// // EXACTLY like the TF pattern:
// service := api.ZIAService
// advSettings, err := advanced_settings.GetAdvancedSettings(ctx, service)
// if err != nil {
// log.Fatal(err)
// }
// jsonPayload := []*advanced_settings.AdvancedSettings{advSettings}
// resourceCount = len(jsonPayload)
// m, _ := json.Marshal(jsonPayload)
// _ = json.Unmarshal(m, &jsonStructData)

case "zia_advanced_settings":
if api.ZIAService == nil {
log.Fatal("ZIA service is not initialized")
Expand Down Expand Up @@ -1722,6 +1708,27 @@ func generate(ctx context.Context, cmd *cobra.Command, writer io.Writer, resourc
continue
}

// Ensure proper Heredoc formatting for multi-line string attributes
if attrName == "quarantine_custom_notification_text" {
value := structData[apiAttrName]
if value != nil {
valueStr := strings.TrimSpace(value.(string))
formattedValue := helpers.FormatHeredoc(valueStr)
output += fmt.Sprintf(" %s = <<-EOT\n%s\nEOT\n\n", attrName, formattedValue)
continue
}
}

// Ensure proper Heredoc formatting for multi-line string attributes
if attrName == "plain_text_message" || attrName == "html_message" || attrName == "subject" {
value := structData[apiAttrName]
if value != nil {
valueStr := strings.TrimSpace(value.(string))
formattedValue := helpers.FormatHeredoc(valueStr) // Use the updated helper function
output += fmt.Sprintf(" %s = <<-EOT\n%s\nEOT\n\n", attrName, formattedValue)
continue
}
}
ty := r.Block.Attributes[attrName].AttributeType

// (A) ADD THIS BLOCK:
Expand Down Expand Up @@ -1812,15 +1819,6 @@ func generate(ctx context.Context, cmd *cobra.Command, writer io.Writer, resourc
if strValue, ok := value.(string); ok {
value = strValue
}
} else if resourceType == "zia_dlp_notification_templates" && helpers.IsInList(attrName, []string{"subject", "plain_text_message", "html_message"}) {
valueStr := strings.ReplaceAll(value.(string), "$", "$$")
formattedValue := helpers.FormatHeredoc(valueStr)
switch attrName {
case "html_message", "plain_text_message":
output += fmt.Sprintf(" %s = <<-EOT\n%sEOT\n\n", attrName, formattedValue)
case "subject":
output += fmt.Sprintf(" %s = <<-EOT\n%sEOT\n", attrName, formattedValue)
}
}
output += nesting.WriteAttrLine(attrName, value, false)

Expand Down
5 changes: 3 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,6 @@ func importResource(ctx context.Context, cmd *cobra.Command, writer io.Writer, r
if api.ZIAService == nil {
log.Fatal("ZIA service is not initialized")
}
// EXACTLY like the TF pattern:
service := api.ZIAService
gws, err := zpa_gateways.GetAll(ctx, service)
if err != nil {
Expand All @@ -1137,10 +1136,12 @@ func importResource(ctx context.Context, cmd *cobra.Command, writer io.Writer, r
if helpers.IsInList(gw.Name, []string{"Auto ZPA Gateway"}) {
continue
}
// Ensure type is always "ZPA"
gw.Type = "ZPA"
gwsFiltered = append(gwsFiltered, gw)
}
m, _ := json.Marshal(gwsFiltered)
resourceCount = len(gwsFiltered)
m, _ := json.Marshal(gwsFiltered)
_ = json.Unmarshal(m, &jsonStructData)
case "zia_sandbox_rules":
if api.ZIAService == nil {
Expand Down
14 changes: 13 additions & 1 deletion docs/guides/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ Track all Zscaler Terraformer Tool releases. New resources, features, and bug fi

---

``Last updated: v2.0.0``
``Last updated: v2.0.1``

---

## 2.0.1 (January, 31 2025)

### Notes

- Release date: **(January, 31 2025)**
- Supported Terraform version: **v1.x.x**

### Bug Fixes
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resource for `zia_dlp_notification_templates` due to heredoc missformatting. - [Issue #253](https://github.com/zscaler/zscaler-terraformer/issues/253)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resource for `zia_end_user_notification` due to heredoc missformatting and attribute validation issue. - [Issue #254](https://github.com/zscaler/zscaler-terraformer/issues/254)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resources for: `zia_forwarding_control_rule` due to missing attribute `id` within the `zpa_gateway` block. - [Issue #255](https://github.com/zscaler/zscaler-terraformer/issues/255)
- [PR #257](https://github.com/zscaler/zscaler-terraformer/pull/257). Fixed ZIA import resources for: `zia_forwarding_control_zpa_gateway` due to missing attribute `type`. - [Issue #256](https://github.com/zscaler/zscaler-terraformer/issues/256)

## 2.0.0 (January, 29 2025) - BREAKING CHANGES

Expand Down
4 changes: 3 additions & 1 deletion terraformutils/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ func FormatHeredoc(value string) string {
for i, line := range lines {
trimmedLine := strings.TrimSpace(line)
if trimmedLine != "" {
formatted += fmt.Sprintf("%s\n", trimmedLine)
// Escape `$` to `$$` to prevent Terraform interpretation issues
escapedLine := strings.ReplaceAll(trimmedLine, "$", "$$")
formatted += fmt.Sprintf("%s\n", escapedLine)
} else if i != len(lines)-1 {
formatted += "\n"
}
Expand Down
3 changes: 3 additions & 0 deletions terraformutils/nesting/nesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import (
var log = logrus.New()

var noSkipIDBlocks = map[string]map[string]bool{
"zia_forwarding_control_rule": {
"zpa_gateway": true,
},
"zia_firewall_dns_rule": {
"dns_gateway": true,
},
Expand Down
Loading