Skip to content

Commit a342eeb

Browse files
authored
fix(terraform): Handle attributes transitioning from plaintext to encrypted (#689)
1 parent da168bd commit a342eeb

5 files changed

Lines changed: 530 additions & 26 deletions

File tree

assets/terraform/test/resource_ike_gateway_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider_test
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/config"
@@ -322,6 +323,25 @@ func TestAccIkeGateway_ProtocolIkev2(t *testing.T) {
322323
})
323324
}
324325

326+
func TestAccIkeGateway_PlaintextValueMissingRejected(t *testing.T) {
327+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
328+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
329+
330+
resource.ParallelTest(t, resource.TestCase{
331+
PreCheck: func() { testAccPreCheck(t) },
332+
ProtoV6ProviderFactories: testAccProviders,
333+
Steps: []resource.TestStep{
334+
{
335+
Config: ikeGatewayConfig_PlaintextValueMissing,
336+
ConfigVariables: map[string]config.Variable{
337+
"prefix": config.StringVariable(prefix),
338+
},
339+
ExpectError: regexp.MustCompile(`The attribute at path.+`),
340+
},
341+
},
342+
})
343+
}
344+
325345
const ikeGatewayConfig_Basic = `
326346
variable "prefix" { type = string }
327347
@@ -760,3 +780,42 @@ resource "panos_template" "example" {
760780
name = format("%s-tmpl", var.prefix)
761781
}
762782
`
783+
784+
const ikeGatewayConfig_PlaintextValueMissing = `
785+
variable "prefix" { type = string }
786+
787+
resource "panos_ike_gateway" "example" {
788+
location = { template = { name = panos_template.example.name } }
789+
790+
name = format("%s-gw1", var.prefix)
791+
792+
authentication = {
793+
pre_shared_key = {
794+
key = "[PLAINTEXT-VALUE-MISSING]"
795+
}
796+
}
797+
798+
local_address = {
799+
interface = panos_ethernet_interface.example.name
800+
}
801+
802+
peer_address = {
803+
ip = "10.10.0.1/32"
804+
}
805+
}
806+
807+
resource "panos_ethernet_interface" "example" {
808+
location = { template = { name = panos_template.example.name, vsys = "vsys1" } }
809+
810+
name = "ethernet1/1"
811+
812+
layer3 = {
813+
ips = [{ name = "10.0.0.1/32" }]
814+
}
815+
}
816+
817+
resource "panos_template" "example" {
818+
location = { panorama = {} }
819+
name = format("%s-tmpl", var.prefix)
820+
}
821+
`

cmd/codegen/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"flag"
66
"fmt"
7-
"log"
87
"log/slog"
98
"os"
109

@@ -32,13 +31,16 @@ func parseFlags() Config {
3231
func runCommand(ctx context.Context, cmdType properties.CommandType, cfg string) {
3332
cmd, err := codegen.NewCommand(ctx, cmdType, cfg)
3433
if err != nil {
35-
log.Fatalf("Failed to create command: %s", err)
34+
slog.Error("Failed to create command", "error", err)
35+
os.Exit(1)
3636
}
3737
if err := cmd.Setup(); err != nil {
38-
log.Fatalf("Setup failed: %s", err)
38+
slog.Error("Setup failed", "error", err)
39+
os.Exit(1)
3940
}
4041
if err := cmd.Execute(); err != nil {
41-
log.Fatalf("Execution failed: %s", err)
42+
slog.Error("Execution failed", "error", err)
43+
os.Exit(1)
4244
}
4345
}
4446

@@ -62,7 +64,6 @@ func main() {
6264
cfg := parseFlags()
6365

6466
ctx := context.Background()
65-
log.SetFlags(log.Ldate | log.Lshortfile)
6667

6768
// Log the operation type and configuration file being used
6869
opTypeMessage := "Operation type: "
@@ -90,5 +91,5 @@ func main() {
9091
runCommand(ctx, properties.CommandTypeTerraform, cfg.ConfigFile)
9192
}
9293

93-
log.Println("Generation complete.")
94+
slog.Info("Generation complete")
9495
}

0 commit comments

Comments
 (0)