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

Added capability to put login banner using general_settings #372

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/resources/general_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The following arguments are supported:
* `domain` - The domain.
* `update_server` - The update server (Default: `updates.paloaltonetworks.com`).
* `verify_update_server` - Verify update server identity (Default: `true`).
* `login_banner` - Login banner that is shown during the login page
* `proxy_server` - (1.5+) Specify a proxy server.
* `proxy_port` - (int, 1.5+) Proxy's port number.
* `proxy_username` - (1.5+) Proxy's username.
Expand Down
8 changes: 8 additions & 0 deletions panos/resource_general_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func resourceGeneralSettings() *schema.Resource {
Computed: true,
Description: "NTP symmetric-key auth key",
},
"login_banner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Banner shown in login page",
},
},
}
}
Expand Down Expand Up @@ -187,6 +193,7 @@ func parseGeneralSettings(d *schema.ResourceData) general.Config {
NtpSecondaryKeyId: d.Get("ntp_secondary_key_id").(int),
NtpSecondaryAlgorithm: d.Get("ntp_secondary_algorithm").(string),
NtpSecondaryAuthKey: d.Get("ntp_secondary_auth_key").(string),
LoginBanner: d.Get("login_banner").(string),
}
}

Expand Down Expand Up @@ -255,6 +262,7 @@ func readGeneralSettings(d *schema.ResourceData, meta interface{}) error {
d.Set("ntp_secondary_key_id", o.NtpSecondaryKeyId)
d.Set("ntp_secondary_algorithm", o.NtpSecondaryAlgorithm)
d.Set("ntp_secondary_auth_key", o.NtpSecondaryAuthKey)
d.Set("login_banner", o.LoginBanner)

return nil
}
Expand Down
19 changes: 12 additions & 7 deletions panos/resource_general_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ func TestAccPanosGeneralSettings_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccGeneralSettingsConfig("acctest", "10.15.15.15", "10.5.5.5", "10.10.10.10", "autokey"),
Config: testAccGeneralSettingsConfig("acctest", "10.15.15.15", "10.5.5.5", "10.10.10.10", "autokey", "testing_banner"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPanosGeneralSettingsExists("panos_general_settings.test", &o),
testAccCheckPanosGeneralSettingsAttributes(&o, "acctest", "10.15.15.15", "10.5.5.5", "10.10.10.10", "autokey"),
testAccCheckPanosGeneralSettingsAttributes(&o, "acctest", "10.15.15.15", "10.5.5.5", "10.10.10.10", "autokey", "testing_banner"),
),
},
{
Config: testAccGeneralSettingsConfig("ngfw", "10.25.25.25", "10.15.15.15", "10.20.20.20", "none"),
Config: testAccGeneralSettingsConfig("ngfw", "10.25.25.25", "10.15.15.15", "10.20.20.20", "none", "testing_banner"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPanosGeneralSettingsExists("panos_general_settings.test", &o),
testAccCheckPanosGeneralSettingsAttributes(&o, "ngfw", "10.25.25.25", "10.15.15.15", "10.20.20.20", "none"),
testAccCheckPanosGeneralSettingsAttributes(&o, "ngfw", "10.25.25.25", "10.15.15.15", "10.20.20.20", "none", "testing_banner"),
),
},
},
Expand Down Expand Up @@ -63,7 +63,7 @@ func testAccCheckPanosGeneralSettingsExists(n string, o *general.Config) resourc
}
}

func testAccCheckPanosGeneralSettingsAttributes(o *general.Config, h, ps, ds, nsa, nsat string) resource.TestCheckFunc {
func testAccCheckPanosGeneralSettingsAttributes(o *general.Config, h, ps, ds, nsa, nsat, loginBanner string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if o.Hostname != h {
return fmt.Errorf("Hostname is %s, expected %s", o.Hostname, h)
Expand All @@ -85,18 +85,23 @@ func testAccCheckPanosGeneralSettingsAttributes(o *general.Config, h, ps, ds, ns
return fmt.Errorf("Hostname is %s, expected %s", o.NtpSecondaryAuthType, nsat)
}

if o.LoginBanner != loginBanner {
return fmt.Errorf("Login Banner is %s, expected %s", o.LoginBanner, loginBanner)
}

return nil
}
}

func testAccGeneralSettingsConfig(h, ps, ds, nsa, nsat string) string {
func testAccGeneralSettingsConfig(h, ps, ds, nsa, nsat, loginBanner string) string {
return fmt.Sprintf(`
resource "panos_general_settings" "test" {
hostname = "%s"
panorama_secondary = "%s"
dns_secondary = "%s"
ntp_secondary_address = "%s"
ntp_secondary_auth_type = "%s"
login_banner = "%s"
}
`, h, ps, ds, nsa, nsat)
`, h, ps, ds, nsa, nsat, loginBanner)
}