diff --git a/bigip/provider.go b/bigip/provider.go index b5546ce56..75aea19a9 100644 --- a/bigip/provider.go +++ b/bigip/provider.go @@ -189,6 +189,7 @@ func Provider() *schema.Provider { "bigip_ltm_cipher_rule": resourceBigipLtmCipherRule(), "bigip_ltm_cipher_group": resourceBigipLtmCipherGroup(), "bigip_partition": resourceBigipPartition(), + "bigip_ltm_request_log_profile": resourceBigipLtmProfileRequestLog(), }, } p.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { diff --git a/bigip/resource_bigip_ltm_profile_request_log.go b/bigip/resource_bigip_ltm_profile_request_log.go new file mode 100644 index 000000000..016ae3d59 --- /dev/null +++ b/bigip/resource_bigip_ltm_profile_request_log.go @@ -0,0 +1,352 @@ +/* +Copyright 2024 F5 Networks Inc. +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ +package bigip + +import ( + "context" + "log" + "os" + "strings" + + bigip "github.com/f5devcentral/go-bigip" + "github.com/f5devcentral/go-bigip/f5teem" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceBigipLtmProfileRequestLog() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceBigipLtmProfileRequestLogCreate, + ReadContext: resourceBigipLtmProfileRequestLogRead, + UpdateContext: resourceBigipLtmProfileRequestLogUpdate, + DeleteContext: resourceBigipLtmProfileRequestLogDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Name of the Request Logging profile", + ValidateFunc: validateF5NameWithDirectory, + }, + "defaults_from": { + Type: schema.TypeString, + Optional: true, + Default: "/Common/request-log", + Description: "Specifies the profile from which this profile inherits settings. The default is the system-supplied `request-log` profile", + ValidateFunc: validateF5Name, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "User defined description for Request Logging profile", + }, + "request_logging": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "disabled", + "enabled"}, false), + Description: "Enables or disables request logging. The default is `disabled`", + }, + "requestlog_protocol": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "mds-udp", + "mds-tcp"}, false), + Description: "Specifies the protocol to be used for high-speed logging of requests. The default is `mds-udp`", + }, + "requestlog_template": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the directives and entries to be logged.", + }, + "requestlog_error_template": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the directives and entries to be logged.", + }, + "requestlog_error_protocol": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "mds-udp", + "mds-tcp"}, false), + Description: "Defines the protocol to be used for high-speed logging of request errors. The default is `mds-udp`", + }, + "requestlog_pool": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool to send logs to. Typically, the pool will contain one or more syslog servers. It is recommended that you create a pool specifically for logging requests. The default is None", + }, + "requestlog_error_pool": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool associated with logging request errors. The default is None.", + }, + "proxy_response": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool associated with logging request errors. The default is None.", + }, + "proxyclose_on_error": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool associated with logging request errors. The default is None.", + }, + "proxyrespond_on_loggingerror": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool associated with logging request errors. The default is None.", + }, + "response_logging": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "disabled", + "enabled"}, false), + Description: "Enables or disables response logging. The default is `disabled`", + }, + "responselog_template": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the directives and entries to be logged.", + }, + "responselog_error_template": { + Type: schema.TypeString, + Optional: true, + Description: "Specifies the directives and entries to be logged.", + }, + "responselog_protocol": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "mds-udp", + "mds-tcp"}, false), + Description: "Specifies the protocol to be used for high-speed logging of responses. The default is `mds-udp`", + }, + "responselog_error_protocol": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "mds-udp", + "mds-tcp"}, false), + Description: "Defines the protocol to be used for high-speed logging of responses errors. The default is `mds-udp`", + }, + "responselog_pool": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool to send logs to. Typically, the pool contains one or more syslog servers. It is recommended that you create a pool specifically for logging responses. The default is None", + }, + "responselog_error_pool": { + Type: schema.TypeString, + Optional: true, + Description: "Defines the pool associated with logging response errors. The default is None.", + }, + }, + } +} + +func resourceBigipLtmProfileRequestLogCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client := meta.(*bigip.BigIP) + name := d.Get("name").(string) + log.Printf("[INFO] Creating Request Log Profile:%+v ", name) + + pss := &bigip.RequestLogProfile{ + Name: name, + } + config := getRequestLogProfileConfig(d, pss) + + err := client.AddRequestLogProfile(config) + if err != nil { + return diag.FromErr(err) + } + d.SetId(name) + + if !client.Teem { + id := uuid.New() + uniqueID := id.String() + assetInfo := f5teem.AssetInfo{ + Name: "Terraform-provider-bigip", + Version: client.UserAgent, + Id: uniqueID, + } + apiKey := os.Getenv("TEEM_API_KEY") + teemDevice := f5teem.AnonymousClient(assetInfo, apiKey) + f := map[string]interface{}{ + "Terraform Version": client.UserAgent, + } + tsVer := strings.Split(client.UserAgent, "/") + err = teemDevice.Report(f, "bigip_ltm_request_log_profile", tsVer[3]) + if err != nil { + log.Printf("[ERROR]Sending Telemetry data failed:%v", err) + } + } + return resourceBigipLtmProfileRequestLogRead(ctx, d, meta) +} + +func resourceBigipLtmProfileRequestLogRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client := meta.(*bigip.BigIP) + + name := d.Id() + + log.Println("[INFO] Fetching HTTP Profile " + name) + + pp, err := client.GetRequestLogProfile(name) + if err != nil { + log.Printf("[ERROR] Unable to retrieve Request Log Profile (%s) ", err) + return diag.FromErr(err) + } + if pp == nil { + log.Printf("[WARN] Request Log Profile (%s) not found, removing from state", name) + d.SetId("") + return nil + } + _ = d.Set("name", name) + _ = d.Set("defaults_from", pp.DefaultsFrom) + + if _, ok := d.GetOk("request_logging"); ok { + _ = d.Set("request_logging", pp.RequestLogging) + } + if _, ok := d.GetOk("requestlog_pool"); ok { + _ = d.Set("requestlog_pool", pp.RequestLogPool) + } + if _, ok := d.GetOk("description"); ok { + _ = d.Set("description", pp.Description) + } + if _, ok := d.GetOk("requestlog_error_pool"); ok { + _ = d.Set("requestlog_error_pool", pp.RequestLogErrorPool) + } + if _, ok := d.GetOk("requestlog_template"); ok { + _ = d.Set("requestlog_template", pp.RequestLogTemplate) + } + if _, ok := d.GetOk("requestlog_protocol"); ok { + _ = d.Set("requestlog_protocol", pp.RequestLogProtocol) + } + if _, ok := d.GetOk("requestlog_error_protocol"); ok { + _ = d.Set("requestlog_error_protocol", pp.RequestLogErrorProtocol) + } + if _, ok := d.GetOk("responselog_protocol"); ok { + _ = d.Set("responselog_protocol", pp.ResponseLogProtocol) + } + if _, ok := d.GetOk("responselog_error_protocol"); ok { + _ = d.Set("responselog_error_protocol", pp.ResponseLogErrorProtocol) + } + if _, ok := d.GetOk("responselog_pool"); ok { + _ = d.Set("responselog_pool", pp.ResponseLogPool) + } + if _, ok := d.GetOk("responselog_error_pool"); ok { + _ = d.Set("responselog_error_pool", pp.ResponseLogErrorPool) + } + if _, ok := d.GetOk("proxy_response"); ok { + _ = d.Set("proxy_response", pp.ProxyResponse) + } + if _, ok := d.GetOk("proxyclose_on_error"); ok { + _ = d.Set("proxyclose_on_error", pp.ProxyCloseOnError) + } + if _, ok := d.GetOk("proxyrespond_on_loggingerror"); ok { + _ = d.Set("proxyrespond_on_loggingerror", pp.ProxyRespondOnLoggingError) + } + if _, ok := d.GetOk("response_logging"); ok { + _ = d.Set("response_logging", pp.RequestLogging) + } + if _, ok := d.GetOk("responselog_template"); ok { + _ = d.Set("responselog_template", pp.RequestLogTemplate) + } + if _, ok := d.GetOk("requestlog_error_template"); ok { + _ = d.Set("requestlog_error_template", pp.RequestLogTemplate) + } + if _, ok := d.GetOk("responselog_error_template"); ok { + _ = d.Set("responselog_error_template", pp.RequestLogTemplate) + } + // if _, ok := d.GetOk("request_chunking"); ok { + // _ = d.Set("request_chunking", pp.RequestChunking) + // } + // if _, ok := d.GetOk("response_chunking"); ok { + // _ = d.Set("response_chunking", pp.ResponseChunking) + // } + // _ = d.Set("response_headers_permitted", pp.ResponseHeadersPermitted) + + // if _, ok := d.GetOk("server_agent_name"); ok { + // _ = d.Set("server_agent_name", pp.ServerAgentName) + // } + // if _, ok := d.GetOk("via_host_name"); ok { + // _ = d.Set("via_host_name", pp.ViaHostName) + // } + // if _, ok := d.GetOk("via_request"); ok { + // _ = d.Set("via_request", pp.ViaRequest) + // } + // if _, ok := d.GetOk("via_response"); ok { + // _ = d.Set("via_response", pp.ViaResponse) + // } + // _ = d.Set("xff_alternative_names", pp.XffAlternativeNames) + return nil +} + +func resourceBigipLtmProfileRequestLogUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client := meta.(*bigip.BigIP) + name := d.Id() + log.Printf("[INFO] Updating Request Log Profile:%+v ", name) + + pss := &bigip.RequestLogProfile{ + Name: name, + } + config := getRequestLogProfileConfig(d, pss) + + err := client.ModifyRequestLogProfile(name, config) + + if err != nil { + log.Printf("[ERROR] Unable to Modify Request Log Profile (%s) (%v)", name, err) + return diag.FromErr(err) + } + + return resourceBigipLtmProfileRequestLogRead(ctx, d, meta) +} + +func resourceBigipLtmProfileRequestLogDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client := meta.(*bigip.BigIP) + + name := d.Id() + log.Println("[INFO] Deleting Request Log Profile " + name) + err := client.DeleteRequestLogProfile(name) + if err != nil { + log.Printf("[ERROR] Unable to Delete Request Log Profile (%s) (%v) ", name, err) + return diag.FromErr(err) + } + d.SetId("") + return nil +} + +func getRequestLogProfileConfig(d *schema.ResourceData, config *bigip.RequestLogProfile) *bigip.RequestLogProfile { + config.DefaultsFrom = d.Get("defaults_from").(string) + config.Description = d.Get("description").(string) + config.RequestLogPool = d.Get("requestlog_pool").(string) + config.RequestLogProtocol = d.Get("requestlog_protocol").(string) + config.RequestLogErrorPool = d.Get("requestlog_error_pool").(string) + config.RequestLogErrorProtocol = d.Get("requestlog_error_protocol").(string) + config.ResponseLogPool = d.Get("responselog_pool").(string) + config.ResponseLogProtocol = d.Get("responselog_protocol").(string) + config.ResponseLogErrorPool = d.Get("responselog_error_pool").(string) + config.ResponseLogErrorProtocol = d.Get("responselog_error_protocol").(string) + config.RequestLogging = d.Get("request_logging").(string) + config.ResponseLogging = d.Get("response_logging").(string) + config.RequestLogTemplate = d.Get("requestlog_template").(string) + config.RequestLogErrorTemplate = d.Get("requestlog_error_template").(string) + config.ResponseLogTemplate = d.Get("responselog_template").(string) + config.ResponseLogErrorTemplate = d.Get("responselog_error_template").(string) + config.ProxyResponse = d.Get("proxy_response").(string) + config.ProxyCloseOnError = d.Get("proxyclose_on_error").(string) + config.ProxyRespondOnLoggingError = d.Get("proxyrespond_on_loggingerror").(string) + return config +} diff --git a/bigip/resource_bigip_ltm_profile_request_log_test.go b/bigip/resource_bigip_ltm_profile_request_log_test.go new file mode 100644 index 000000000..b67ac4b10 --- /dev/null +++ b/bigip/resource_bigip_ltm_profile_request_log_test.go @@ -0,0 +1,164 @@ +/* +Copyright 2019 F5 Networks Inc. +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ +package bigip + +import ( + "fmt" + "strings" + "testing" + + bigip "github.com/f5devcentral/go-bigip" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +var resRequestLogName = "bigip_ltm_request_log_profile" + +func TestAccBigipLtmProfileRequestLogTC1(t *testing.T) { + t.Parallel() + var instName = "request-log-profile-tc1" + var testPartition = "Common" + var testRequestLogProfileName = fmt.Sprintf("/%s/%s", testPartition, instName) + resFullName := fmt.Sprintf("%s.%s", resRequestLogName, instName) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAcctPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testCheckProfileRequestLogDestroyed, + Steps: []resource.TestStep{ + { + Config: testAccBigipLtmProfileRequestLogTC1Config(testPartition, testRequestLogProfileName, instName), + Check: resource.ComposeTestCheckFunc( + testCheckRequestLogExists(testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "name", testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/request-log"), + ), + }, + }, + }) +} + +func TestAccBigipLtmProfileRequestLogTC2(t *testing.T) { + t.Parallel() + var instName = "request-log-profile-tc2" + var testPartition = "Common" + var testRequestLogProfileName = fmt.Sprintf("/%s/%s", testPartition, instName) + resFullName := fmt.Sprintf("%s.%s", resRequestLogName, instName) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAcctPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testCheckProfileRequestLogDestroyed, + Steps: []resource.TestStep{ + { + Config: testAccBigipLtmProfileRequestLogTC1Config(testPartition, testRequestLogProfileName, instName), + Check: resource.ComposeTestCheckFunc( + testCheckRequestLogExists(testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "name", testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/request-log"), + ), + }, + { + Config: testAccBigipLtmProfileRequestLogTC2Config(testPartition, testRequestLogProfileName, instName), + Check: resource.ComposeTestCheckFunc( + testCheckRequestLogExists(testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "name", testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/request-log"), + resource.TestCheckResourceAttr(resFullName, "request_logging", "disabled"), + resource.TestCheckResourceAttr(resFullName, "requestlog_protocol", "mds-tcp"), + resource.TestCheckResourceAttr(resFullName, "requestlog_error_protocol", "mds-tcp"), + ), + }, + { + Config: testAccBigipLtmProfileRequestLogTC2UpdateConfig(testPartition, testRequestLogProfileName, instName), + Check: resource.ComposeTestCheckFunc( + testCheckRequestLogExists(testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "name", testRequestLogProfileName), + resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/request-log"), + resource.TestCheckResourceAttr(resFullName, "request_logging", "enabled"), + resource.TestCheckResourceAttr(resFullName, "requestlog_protocol", "mds-udp"), + resource.TestCheckResourceAttr(resFullName, "requestlog_error_protocol", "mds-udp"), + ), + }, + }, + }) +} + +func testCheckRequestLogExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*bigip.BigIP) + p, err := client.GetRequestLogProfile(name) + if err != nil { + return err + } + if p == nil { + return fmt.Errorf("http %s was not created", name) + } + + return nil + } +} + +func testCheckProfileRequestLogDestroyed(s *terraform.State) error { + client := testAccProvider.Meta().(*bigip.BigIP) + + for _, rs := range s.RootModule().Resources { + if rs.Type != resRequestLogName { + continue + } + name := rs.Primary.ID + http, err := client.GetRequestLogProfile(name) + if err != nil { + if strings.Contains(err.Error(), "not found") { + return nil + } + return err + } + if http != nil { + return fmt.Errorf("http %s not destroyed ", name) + } + } + return nil +} + +func testAccBigipLtmProfileRequestLogTC1Config(partition, profileName, resourceName string) string { + return fmt.Sprintf(` +resource "%[4]s" "%[3]s" { + name = "%[2]s" + defaults_from = "/%[1]s/request-log" +} +`, partition, profileName, resourceName, resRequestLogName) +} + +func testAccBigipLtmProfileRequestLogTC2Config(partition, profileName, resourceName string) string { + return fmt.Sprintf(` +resource "%[4]s" "%[3]s" { + name = "%[2]s" + defaults_from = "/%[1]s/request-log" + request_logging = "disabled" + requestlog_protocol = "mds-tcp" + requestlog_error_protocol = "mds-tcp" + responselog_protocol = "mds-tcp" + responselog_error_protocol = "mds-tcp" +} +`, partition, profileName, resourceName, resRequestLogName) +} + +func testAccBigipLtmProfileRequestLogTC2UpdateConfig(partition, profileName, resourceName string) string { + return fmt.Sprintf(` +resource "%[4]s" "%[3]s" { + name = "%[2]s" + defaults_from = "/%[1]s/request-log" + request_logging = "enabled" + requestlog_protocol = "mds-udp" + requestlog_error_protocol = "mds-udp" + responselog_protocol = "mds-udp" + responselog_error_protocol = "mds-udp" +} +`, partition, profileName, resourceName, resRequestLogName) +} diff --git a/bigip/version.go b/bigip/version.go index 0f3e13ff5..6f9dbec86 100644 --- a/bigip/version.go +++ b/bigip/version.go @@ -1,4 +1,4 @@ package bigip // ProviderVersion is set at build-time in the release process -var ProviderVersion = "1.20.1" +var ProviderVersion = "1.20.2" diff --git a/docs/resources/bigip_ltm_request_log_profile.md b/docs/resources/bigip_ltm_request_log_profile.md new file mode 100644 index 000000000..67e9eb209 --- /dev/null +++ b/docs/resources/bigip_ltm_request_log_profile.md @@ -0,0 +1,70 @@ +--- +layout: "bigip" +page_title: "BIG-IP: bigip_ltm_request_log_profile" +subcategory: "Local Traffic Manager(LTM)" +description: |- + Provides details about bigip_ltm_request_log_profile resource +--- + +# bigip\_ltm\_request\_log\_profile + +`bigip_ltm_request_log_profile` Resource used for Configures request logging using the Request Logging profile + +## Example Usage + +```hcl +resource "bigip_ltm_request_log_profile" "request-log-profile-tc1-child" { + name = "/Common/request-log-profile-tc1-child" + defaults_from = bigip_ltm_request_log_profile.request-log-profile-tc1.name + request_logging = "disabled" + requestlog_pool = "/Common/pool2" + requestlog_error_pool = "/Common/pool1" + requestlog_protocol = "mds-tcp" + requestlog_error_protocol = "mds-tcp" + responselog_protocol = "mds-tcp" + responselog_error_protocol = "mds-tcp" +} + +``` + +## Argument Reference + +* `name` (Required,type `string`) Name of the Request Logging profile,name of Profile should be full path. Full path is the combination of the `partition + profile name`,For example `/Common/request-log-profile-tc1`. + +* `defaults_from` - (optional,type `string`) Specifies the profile from which this profile inherits settings. The default is the system-supplied `request-log` profile. + +* `description` - (optional,type `string`) Specifies user-defined description. + +* `request_logging` - (Optional,type `string`) Enables or disables request logging. The default is `disabled`, possible values are `enabled` and `disabled`. + +* `requestlog_protocol` - (Optional) Specifies the protocol to be used for high-speed logging of requests. The default is `mds-udp`,possible values are `mds-udp` and `mds-tcp`. + +* `requestlog_template` - (Optional) Specifies the directives and entries to be logged. More infor on requestlog_template can be found [here](https://techdocs.f5.com/en-us/bigip-15-0-0/external-monitoring-of-big-ip-systems-implementations/configuring-request-logging.html). how to use can be find [here](https://my.f5.com/manage/s/article/K00847516). + +* `requestlog_error_template` - (Optional) Specifies the directives and entries to be logged for request errors. + +* `requestlog_pool` - (Optional) Defines the pool to send logs to. Typically, the pool will contain one or more syslog servers. It is recommended that you create a pool specifically for logging requests. The default is `none`. + +* `requestlog_error_protocol` - (Optional) Specifies the protocol to be used for high-speed logging of request errors. The default is `mds-udp`,possible values are `mds-udp` and `mds-tcp`. + +* `response_logging` - (Optional,type `string`) Enables or disables response logging. The default is `disabled`, possible values are `enabled` and `disabled`. + +* `responselog_protocol` - (Optional) Specifies the protocol to be used for high-speed logging of responses. The default is `mds-udp`,possible values are `mds-udp` and `mds-tcp`. + +* `responselog_error_protocol` - (Optional) Specifies the protocol to be used for high-speed logging of response errors. The default is `mds-udp`,possible values are `mds-udp` and `mds-tcp`. + +* `responselog_pool` - (Optional) Defines the pool to send logs to. Typically, the pool contains one or more syslog servers. It is recommended that you create a pool specifically for logging responses. The default is `none`. + +* `responselog_error_pool` - (Optional) Defines the pool associated with logging response errors. The default is `none`. + +* `responselog_template` - (Optional) Specifies the directives and entries to be logged. More infor on responselog_template can be found [here](https://techdocs.f5.com/en-us/bigip-15-0-0/external-monitoring-of-big-ip-systems-implementations/configuring-request-logging.html). how to use can be find [here](https://my.f5.com/manage/s/article/K00847516). + +* `responselog_error_template` - (Optional) Specifies the directives and entries to be logged for request errors. + +## Import + +BIG-IP LTM Request Log profiles can be imported using the `name`, e.g. + +```bash +terraform import bigip_ltm_request_log_profile.test-request-log /Common/test-request-log +``` diff --git a/vendor/github.com/f5devcentral/go-bigip/gtm.go b/vendor/github.com/f5devcentral/go-bigip/gtm.go index b106147c6..bc35d9444 100644 --- a/vendor/github.com/f5devcentral/go-bigip/gtm.go +++ b/vendor/github.com/f5devcentral/go-bigip/gtm.go @@ -10,8 +10,10 @@ See the License for the specific language governing permissions and limitations */ package bigip -import "encoding/json" -import "log" +import ( + "encoding/json" + "log" +) //ooo @@ -142,7 +144,6 @@ const ( uriServer = "server" uriDatacenter = "datacenter" uriGtmmonitor = "monitor" - uriHttp = "http" uriPool_a = "pool/a" ) diff --git a/vendor/github.com/f5devcentral/go-bigip/ltm.go b/vendor/github.com/f5devcentral/go-bigip/ltm.go index 190540cf4..4955055ba 100644 --- a/vendor/github.com/f5devcentral/go-bigip/ltm.go +++ b/vendor/github.com/f5devcentral/go-bigip/ltm.go @@ -1980,6 +1980,8 @@ const ( uriCreateDraft = "?options=create-draft" uriRule = "rule" uriWebAcceleration = "web-acceleration" + uriHttp = "http" + uriRequestLog = "request-log" ) var cidr = map[string]string{ @@ -4082,3 +4084,63 @@ func (b *BigIP) GetLtmCipherGroup(name string) (*CipherGroupReq, error) { return &cipherGroup, nil } + +// json to golang struct +type RequestLogProfile struct { + Name string `json:"name,omitempty"` + Partition string `json:"partition,omitempty"` + FullPath string `json:"fullPath,omitempty"` + AppService string `json:"appService,omitempty"` + DefaultsFrom string `json:"defaultsFrom,omitempty"` + Description string `json:"description,omitempty"` + LogRequestLoggingErrors string `json:"logRequestLoggingErrors,omitempty"` + LogResponseByDefault string `json:"logResponseByDefault,omitempty"` + LogResponseLoggingErrors string `json:"logResponseLoggingErrors,omitempty"` + ProxyCloseOnError string `json:"proxyCloseOnError,omitempty"` + ProxyRespondOnLoggingError string `json:"proxyRespondOnLoggingError,omitempty"` + ProxyResponse string `json:"proxyResponse,omitempty"` + RequestLogErrorPool string `json:"requestLogErrorPool,omitempty"` + RequestLogErrorProtocol string `json:"requestLogErrorProtocol,omitempty"` + RequestLogErrorTemplate string `json:"requestLogErrorTemplate,omitempty"` + RequestLogPool string `json:"requestLogPool,omitempty"` + RequestLogProtocol string `json:"requestLogProtocol,omitempty"` + RequestLogTemplate string `json:"requestLogTemplate,omitempty"` + RequestLogging string `json:"requestLogging,omitempty"` + ResponseLogErrorPool string `json:"responseLogErrorPool,omitempty"` + ResponseLogErrorProtocol string `json:"responseLogErrorProtocol,omitempty"` + ResponseLogErrorTemplate string `json:"responseLogErrorTemplate,omitempty"` + ResponseLogPool string `json:"responseLogPool,omitempty"` + ResponseLogProtocol string `json:"responseLogProtocol,omitempty"` + ResponseLogTemplate string `json:"responseLogTemplate,omitempty"` + ResponseLogging string `json:"responseLogging,omitempty"` +} + +// AddRequestLogProfile creates a new Request Log profile on the BIG-IP system. +func (b *BigIP) AddRequestLogProfile(config *RequestLogProfile) error { + return b.post(config, uriLtm, uriProfile, uriRequestLog) +} + +// DeleteRequestLogProfile removes a Request Log profile. +func (b *BigIP) DeleteRequestLogProfile(name string) error { + return b.delete(uriLtm, uriProfile, uriRequestLog, name) +} + +// ModifyRequestLogProfile allows you to change any attribute of a RequestLog profile. +// Fields that can be modified are referenced in the RequestLogProfile struct. +func (b *BigIP) ModifyRequestLogProfile(name string, config *RequestLogProfile) error { + return b.patch(config, uriLtm, uriProfile, uriRequestLog, name) +} + +func (b *BigIP) GetRequestLogProfile(name string) (*RequestLogProfile, error) { + var requestLogProfile RequestLogProfile + err, ok := b.getForEntity(&requestLogProfile, uriLtm, uriProfile, uriRequestLog, name) + if err != nil { + return nil, err + } + + if !ok { + return nil, nil + } + + return &requestLogProfile, nil +}