diff --git a/.changes/issue-593.md b/.changes/issue-593.md index bfc38db9..9c725e84 100644 --- a/.changes/issue-593.md +++ b/.changes/issue-593.md @@ -1,6 +1,8 @@ FEATURES: +* add `junos_system_syslog_user` resource (Fix [#593](https://github.com/jeremmfr/terraform-provider-junos/issues/593)) + ENHANCEMENTS: * **resource/junos_system_syslog_file**: resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) diff --git a/docs/resources/system_syslog_user.md b/docs/resources/system_syslog_user.md new file mode 100644 index 00000000..dd1f5167 --- /dev/null +++ b/docs/resources/system_syslog_user.md @@ -0,0 +1,82 @@ +--- +page_title: "Junos: junos_system_syslog_user" +--- + +# junos_system_syslog_user + +Configure a system syslog user. + +## Example Usage + +```hcl +# Add a system syslog user +resource "junos_system_syslog_user" "all" { + username = "*" + any_severity = "emergency" +} +resource "junos_system_syslog_user" "demo_syslog_user" { + username = "admin" + kernel_severity = "any" +} +``` + +## Argument Reference + +The following arguments are supported: + +- **username** (Required, String, Forces new resource) + Name of user to notify (or `*` for all). +- **allow_duplicates** (Optional, Boolean) + Do not suppress the repeated message. +- **match** (Optional, String) + Regular expression for lines to be logged. +- **match_strings** (Optional, List of String) + Matching string(s) for lines to be logged. +- **any_severity** (Optional, String) + All facilities severity. +- **authorization_severity** (Optional, String) + Authorization system severity. +- **changelog_severity** (Optional, String) + Configuration change log severity. +- **conflictlog_severity** (Optional, String) + Configuration conflict log severity. +- **daemon_severity** (Optional, String) + Various system processes severity. +- **dfc_severity** (Optional, String) + Dynamic flow capture severity. +- **external_severity** (Optional, String) + Local external applications severity. +- **firewall_severity** (Optional, String) + Firewall filtering system severity. +- **ftp_severity** (Optional, String) + FTP process severity. +- **interactivecommands_severity** (Optional, String) + Commands executed by the UI severity. +- **kernel_severity** (Optional, String) + Kernel severity. +- **ntp_severity** (Optional, String) + NTP process severity. +- **pfe_severity** (Optional, String) + Packet Forwarding Engine severity. +- **security_severity** (Optional, String) + Security related severity. +- **user_severity** (Optional, String) + User processes severity. + +**WARNING** All severities need to be +`alert`, `any`, `critical`, `emergency`, `error`, `info`, `none`, `notice` or `warning`. + +## Attributes Reference + +The following attributes are exported: + +- **id** (String) + An identifier for the resource with format ``. + +## Import + +Junos system syslog host can be imported using an id made up of ``, e.g. + +```shell +$ terraform import junos_system_syslog_user.demo_syslog_user admin +``` diff --git a/internal/providerfwk/provider.go b/internal/providerfwk/provider.go index 7486db6e..95183328 100644 --- a/internal/providerfwk/provider.go +++ b/internal/providerfwk/provider.go @@ -281,6 +281,7 @@ func (p *junosProvider) Resources(_ context.Context) []func() resource.Resource newSystemResource, newSystemSyslogFileResource, newSystemSyslogHostResource, + newSystemSyslogUserResource, } } diff --git a/internal/providerfwk/resource_system_syslog_user.go b/internal/providerfwk/resource_system_syslog_user.go new file mode 100644 index 00000000..81cc68a8 --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_user.go @@ -0,0 +1,559 @@ +package providerfwk + +import ( + "context" + "strings" + + "github.com/jeremmfr/terraform-provider-junos/internal/junos" + "github.com/jeremmfr/terraform-provider-junos/internal/tfdiag" + "github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator" + + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + balt "github.com/jeremmfr/go-utils/basicalter" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &systemSyslogUser{} + _ resource.ResourceWithConfigure = &systemSyslogUser{} + _ resource.ResourceWithImportState = &systemSyslogUser{} +) + +type systemSyslogUser struct { + client *junos.Client +} + +func newSystemSyslogUserResource() resource.Resource { + return &systemSyslogUser{} +} + +func (rsc *systemSyslogUser) typeName() string { + return providerName + "_system_syslog_user" +} + +func (rsc *systemSyslogUser) junosName() string { + return "system syslog user" +} + +func (rsc *systemSyslogUser) junosClient() *junos.Client { + return rsc.client +} + +func (rsc *systemSyslogUser) Metadata( + _ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse, +) { + resp.TypeName = rsc.typeName() +} + +func (rsc *systemSyslogUser) Configure( + ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, +) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + client, ok := req.ProviderData.(*junos.Client) + if !ok { + unexpectedResourceConfigureType(ctx, req, resp) + + return + } + rsc.client = client +} + +func (rsc *systemSyslogUser) Schema( + _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, +) { + resp.Schema = schema.Schema{ + Description: defaultResourceSchemaDescription(rsc), + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "An identifier for the resource with format ``.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "username": schema.StringAttribute{ + Required: true, + Description: "Name of user to notify (or `*` for all).", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 250), + stringvalidator.Any( + tfvalidator.StringFormat(tfvalidator.DefaultFormat), + stringvalidator.OneOf("*"), + ), + }, + }, + "allow_duplicates": schema.BoolAttribute{ + Optional: true, + Description: "Do not suppress the repeated message.", + Validators: []validator.Bool{ + tfvalidator.BoolTrue(), + }, + }, + "match": schema.StringAttribute{ + Optional: true, + Description: "Regular expression for lines to be logged.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + }, + }, + "match_strings": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "Matching string(s) for lines to be logged.", + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.ValueStringsAre( + stringvalidator.LengthAtLeast(1), + tfvalidator.StringDoubleQuoteExclusion(), + ), + }, + }, + "any_severity": schema.StringAttribute{ + Optional: true, + Description: "All facilities sseverity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "authorization_severity": schema.StringAttribute{ + Optional: true, + Description: "Authorization system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "changelog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration change log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "conflictlog_severity": schema.StringAttribute{ + Optional: true, + Description: "Configuration conflict log severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "daemon_severity": schema.StringAttribute{ + Optional: true, + Description: "Various system processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "dfc_severity": schema.StringAttribute{ + Optional: true, + Description: "Dynamic flow capture severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "external_severity": schema.StringAttribute{ + Optional: true, + Description: "Local external applications severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "firewall_severity": schema.StringAttribute{ + Optional: true, + Description: "Firewall filtering system severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ftp_severity": schema.StringAttribute{ + Optional: true, + Description: "FTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "interactivecommands_severity": schema.StringAttribute{ + Optional: true, + Description: "Commands executed by the UI severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "kernel_severity": schema.StringAttribute{ + Optional: true, + Description: "Kernel severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "ntp_severity": schema.StringAttribute{ + Optional: true, + Description: "NTP process severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "pfe_severity": schema.StringAttribute{ + Optional: true, + Description: "Packet Forwarding Engine severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "security_severity": schema.StringAttribute{ + Optional: true, + Description: "Security related severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + "user_severity": schema.StringAttribute{ + Optional: true, + Description: "User processes severity.", + Validators: []validator.String{ + stringvalidator.OneOf(junos.SyslogSeverity()...), + }, + }, + }, + } +} + +type systemSyslogUserData struct { + AllowDuplicates types.Bool `tfsdk:"allow_duplicates"` + ID types.String `tfsdk:"id"` + Username types.String `tfsdk:"username"` + Match types.String `tfsdk:"match"` + MatchStrings []types.String `tfsdk:"match_strings"` + AnySeverity types.String `tfsdk:"any_severity"` + AuthorizationSeverity types.String `tfsdk:"authorization_severity"` + ChangelogSeverity types.String `tfsdk:"changelog_severity"` + ConflictlogSeverity types.String `tfsdk:"conflictlog_severity"` + DaemonSeverity types.String `tfsdk:"daemon_severity"` + DfcSeverity types.String `tfsdk:"dfc_severity"` + ExternalSeverity types.String `tfsdk:"external_severity"` + FirewallSeverity types.String `tfsdk:"firewall_severity"` + FtpSeverity types.String `tfsdk:"ftp_severity"` + InteractivecommandsSeverity types.String `tfsdk:"interactivecommands_severity"` + KernelSeverity types.String `tfsdk:"kernel_severity"` + NtpSeverity types.String `tfsdk:"ntp_severity"` + PfeSeverity types.String `tfsdk:"pfe_severity"` + SecuritySeverity types.String `tfsdk:"security_severity"` + UserSeverity types.String `tfsdk:"user_severity"` +} + +func (rsc *systemSyslogUser) Create( + ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse, +) { + var plan systemSyslogUserData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + if plan.Username.ValueString() == "" { + resp.Diagnostics.AddAttributeError( + path.Root("username"), + "Empty Username", + defaultResourceCouldNotCreateWithEmptyMessage(rsc, "username"), + ) + + return + } + + defaultResourceCreate( + ctx, + rsc, + func(fnCtx context.Context, junSess *junos.Session) bool { + userExists, err := checkSystemSyslogUserExists(fnCtx, plan.Username.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PreCheckErrSummary, err.Error()) + + return false + } + if userExists { + resp.Diagnostics.AddError( + tfdiag.DuplicateConfigErrSummary, + defaultResourceAlreadyExistsMessage(rsc, plan.Username), + ) + + return false + } + + return true + }, + func(fnCtx context.Context, junSess *junos.Session) bool { + userExists, err := checkSystemSyslogUserExists(fnCtx, plan.Username.ValueString(), junSess) + if err != nil { + resp.Diagnostics.AddError(tfdiag.PostCheckErrSummary, err.Error()) + + return false + } + if !userExists { + resp.Diagnostics.AddError( + tfdiag.NotFoundErrSummary, + defaultResourceDoesNotExistsAfterCommitMessage(rsc, plan.Username), + ) + + return false + } + + return true + }, + &plan, + resp, + ) +} + +func (rsc *systemSyslogUser) Read( + ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, +) { + var state, data systemSyslogUserData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + var _ resourceDataReadFrom1String = &data + defaultResourceRead( + ctx, + rsc, + []string{ + state.Username.ValueString(), + }, + &data, + nil, + resp, + ) +} + +func (rsc *systemSyslogUser) Update( + ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, +) { + var plan, state systemSyslogUserData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceUpdate( + ctx, + rsc, + &state, + &plan, + resp, + ) +} + +func (rsc *systemSyslogUser) Delete( + ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, +) { + var state systemSyslogUserData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + defaultResourceDelete( + ctx, + rsc, + &state, + resp, + ) +} + +func (rsc *systemSyslogUser) ImportState( + ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, +) { + var data systemSyslogUserData + + var _ resourceDataReadFrom1String = &data + defaultResourceImportState( + ctx, + rsc, + &data, + req, + resp, + defaultResourceImportDontFindIDStrMessage(rsc, req.ID, "username"), + ) +} + +func checkSystemSyslogUserExists( + _ context.Context, username string, junSess *junos.Session, +) ( + bool, error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog user " + username + junos.PipeDisplaySet) + if err != nil { + return false, err + } + if showConfig == junos.EmptyW { + return false, nil + } + + return true, nil +} + +func (rscData *systemSyslogUserData) fillID() { + rscData.ID = types.StringValue(rscData.Username.ValueString()) +} + +func (rscData *systemSyslogUserData) nullID() bool { + return rscData.ID.IsNull() +} + +func (rscData *systemSyslogUserData) set( + _ context.Context, junSess *junos.Session, +) ( + path.Path, error, +) { + configSet := make([]string, 0) + setPrefix := "set system syslog user " + rscData.Username.ValueString() + " " + + if rscData.AllowDuplicates.ValueBool() { + configSet = append(configSet, setPrefix+"allow-duplicates") + } + if v := rscData.Match.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"match \""+v+"\"") + } + for _, v := range rscData.MatchStrings { + configSet = append(configSet, setPrefix+"match-strings \""+v.ValueString()+"\"") + } + if v := rscData.AnySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"any "+v) + } + if v := rscData.AuthorizationSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"authorization "+v) + } + if v := rscData.ChangelogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"change-log "+v) + } + if v := rscData.ConflictlogSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"conflict-log "+v) + } + if v := rscData.DaemonSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"daemon "+v) + } + if v := rscData.DfcSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"dfc "+v) + } + if v := rscData.ExternalSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"external "+v) + } + if v := rscData.FirewallSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"firewall "+v) + } + if v := rscData.FtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ftp "+v) + } + if v := rscData.InteractivecommandsSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"interactive-commands "+v) + } + if v := rscData.KernelSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"kernel "+v) + } + if v := rscData.NtpSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"ntp "+v) + } + if v := rscData.PfeSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"pfe "+v) + } + if v := rscData.SecuritySeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"security "+v) + } + if v := rscData.UserSeverity.ValueString(); v != "" { + configSet = append(configSet, setPrefix+"user "+v) + } + + return path.Empty(), junSess.ConfigSet(configSet) +} + +func (rscData *systemSyslogUserData) read( + _ context.Context, username string, junSess *junos.Session, +) ( + err error, +) { + showConfig, err := junSess.Command(junos.CmdShowConfig + + "system syslog user " + username + junos.PipeDisplaySetRelative) + if err != nil { + return err + } + if showConfig != junos.EmptyW { + rscData.Username = types.StringValue(username) + rscData.fillID() + for _, item := range strings.Split(showConfig, "\n") { + if strings.Contains(item, junos.XMLStartTagConfigOut) { + continue + } + if strings.Contains(item, junos.XMLEndTagConfigOut) { + break + } + itemTrim := strings.TrimPrefix(item, junos.SetLS) + switch { + case itemTrim == "allow-duplicates": + rscData.AllowDuplicates = types.BoolValue(true) + case balt.CutPrefixInString(&itemTrim, "match "): + rscData.Match = types.StringValue(strings.Trim(itemTrim, "\"")) + case balt.CutPrefixInString(&itemTrim, "match-strings "): + rscData.MatchStrings = append(rscData.MatchStrings, + types.StringValue(strings.Trim(itemTrim, "\""))) + case balt.CutPrefixInString(&itemTrim, "any "): + rscData.AnySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "authorization "): + rscData.AuthorizationSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "change-log "): + rscData.ChangelogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "conflict-log "): + rscData.ConflictlogSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "daemon "): + rscData.DaemonSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "dfc "): + rscData.DfcSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "external "): + rscData.ExternalSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "firewall "): + rscData.FirewallSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ftp "): + rscData.FtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "interactive-commands "): + rscData.InteractivecommandsSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "kernel "): + rscData.KernelSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "ntp "): + rscData.NtpSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "pfe "): + rscData.PfeSeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "security "): + rscData.SecuritySeverity = types.StringValue(itemTrim) + case balt.CutPrefixInString(&itemTrim, "user "): + rscData.UserSeverity = types.StringValue(itemTrim) + } + } + } + + return nil +} + +func (rscData *systemSyslogUserData) del( + _ context.Context, junSess *junos.Session, +) error { + configSet := []string{ + "delete system syslog user " + rscData.Username.ValueString(), + } + + return junSess.ConfigSet(configSet) +} diff --git a/internal/providerfwk/resource_system_syslog_user_test.go b/internal/providerfwk/resource_system_syslog_user_test.go new file mode 100644 index 00000000..0106992e --- /dev/null +++ b/internal/providerfwk/resource_system_syslog_user_test.go @@ -0,0 +1,64 @@ +package providerfwk_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceSystemSyslogUser_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "allow_duplicates", "true"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "match", "match testacc"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "any_severity", "emergency"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "changelog_severity", "critical"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "conflictlog_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "daemon_severity", "warning"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "dfc_severity", "alert"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "external_severity", "any"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "firewall_severity", "info"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "ftp_severity", "none"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "interactivecommands_severity", "notice"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "kernel_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "ntp_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "pfe_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "security_severity", "error"), + resource.TestCheckResourceAttr("junos_system_syslog_user.testacc_syslogUser", + "user_severity", "error"), + ), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ConfigDirectory: config.TestStepDirectory(), + }, + { + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + ResourceName: "junos_system_syslog_user.testacc_syslogUser", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf new file mode 100644 index 00000000..556d1786 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/main.tf @@ -0,0 +1,50 @@ +resource "junos_system_syslog_user" "testacc_syslogUser" { + username = "testacc" + + allow_duplicates = true + match = "match testacc" + any_severity = "emergency" + changelog_severity = "critical" + conflictlog_severity = "error" + daemon_severity = "warning" + dfc_severity = "alert" + external_severity = "any" + firewall_severity = "info" + ftp_severity = "none" + interactivecommands_severity = "notice" + kernel_severity = "error" + ntp_severity = "error" + pfe_severity = "error" + security_severity = "error" + user_severity = "error" +} + +resource "local_file" "clear_user_all" { + content = "delete system syslog user *" + filename = "/tmp/testacc/terraform-provider-junos/ResourceSystemSyslogUser_basic_clear_user_all.txt" +} + +resource "junos_null_commit_file" "clear_user_all" { + filename = local_file.clear_user_all.filename +} + +resource "junos_system_syslog_user" "testacc_syslogUserAll" { + depends_on = [junos_null_commit_file.clear_user_all] + + username = "*" + + any_severity = "emergency" + changelog_severity = "emergency" + conflictlog_severity = "emergency" + daemon_severity = "emergency" + dfc_severity = "emergency" + external_severity = "emergency" + firewall_severity = "emergency" + ftp_severity = "emergency" + interactivecommands_severity = "emergency" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" +} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf new file mode 100644 index 00000000..8e7fc8ee --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/1/provider.tf @@ -0,0 +1 @@ +provider "local" {} diff --git a/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf new file mode 100644 index 00000000..ae3f6f45 --- /dev/null +++ b/internal/providerfwk/testdata/TestAccResourceSystemSyslogUser_basic/2/main.tf @@ -0,0 +1,26 @@ +resource "junos_system_syslog_user" "testacc_syslogUser" { + username = "testacc" + + match = "testacc" + match_strings = ["testacc"] + any_severity = "emergency" + changelog_severity = "emergency" + conflictlog_severity = "emergency" + daemon_severity = "emergency" + dfc_severity = "emergency" + external_severity = "emergency" + firewall_severity = "emergency" + ftp_severity = "emergency" + interactivecommands_severity = "error" + kernel_severity = "emergency" + ntp_severity = "emergency" + pfe_severity = "emergency" + security_severity = "emergency" + user_severity = "emergency" +} + +resource "junos_system_syslog_user" "testacc_syslogUserAll" { + username = "*" + + any_severity = "emergency" +}