From 7792d00e28700fa2ef58502542b23f98539ee345 Mon Sep 17 00:00:00 2001 From: Shizhao Liu Date: Mon, 4 Dec 2023 23:14:57 +0000 Subject: [PATCH] Implement Policy resource for LB Http Application Profile Signed-off-by: Shizhao Liu --- nsxt/lb_utils.go | 33 +++ nsxt/provider.go | 1 + ...nsxt_policy_lb_http_application_profile.go | 240 ++++++++++++++++++ ...policy_lb_http_application_profile_test.go | 221 ++++++++++++++++ ..._lb_http_application_profile.html.markdown | 72 ++++++ 5 files changed, 567 insertions(+) create mode 100644 nsxt/resource_nsxt_policy_lb_http_application_profile.go create mode 100644 nsxt/resource_nsxt_policy_lb_http_application_profile_test.go create mode 100644 website/docs/r/policy_lb_http_application_profile.html.markdown diff --git a/nsxt/lb_utils.go b/nsxt/lb_utils.go index d408eff6a..e6d77aeb1 100644 --- a/nsxt/lb_utils.go +++ b/nsxt/lb_utils.go @@ -11,6 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/vmware/go-vmware-nsxt/loadbalancer" + "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" ) // Helpers for common LB monitor schema settings @@ -237,3 +239,34 @@ func resourceNsxtLbMonitorDelete(d *schema.ResourceData, m interface{}) error { } return nil } + +func resourceNsxtPolicyLBAppProfileExists(id string, connector client.Connector, isGlobalManager bool) (bool, error) { + client := infra.NewLbAppProfilesClient(connector) + _, err := client.Get(id) + if err == nil { + return true, nil + } + + if isNotFoundError(err) { + return false, nil + } + msg := fmt.Sprintf("Error retrieving resource LBAppProfile") + return false, logAPIError(msg, err) +} + +func resourceNsxtPolicyLBAppProfileDelete(d *schema.ResourceData, m interface{}) error { + id := d.Id() + if id == "" { + return fmt.Errorf("Error obtaining LBAppProfile ID") + } + + connector := getPolicyConnector(m) + forceParam := true + client := infra.NewLbAppProfilesClient(connector) + err := client.Delete(id, &forceParam) + if err != nil { + return handleDeleteError("LBAppProfile", id, err) + } + + return nil +} diff --git a/nsxt/provider.go b/nsxt/provider.go index 2200d860f..99acebc39 100644 --- a/nsxt/provider.go +++ b/nsxt/provider.go @@ -437,6 +437,7 @@ func Provider() *schema.Provider { "nsxt_edge_high_availability_profile": resourceNsxtEdgeHighAvailabilityProfile(), "nsxt_policy_host_transport_node_collection": resourceNsxtPolicyHostTransportNodeCollection(), "nsxt_policy_lb_client_ssl_profile": resourceNsxtPolicyLBClientSslProfile(), + "nsxt_policy_lb_http_application_profile": resourceNsxtPolicyLBHttpApplicationProfile(), }, ConfigureFunc: providerConfigure, diff --git a/nsxt/resource_nsxt_policy_lb_http_application_profile.go b/nsxt/resource_nsxt_policy_lb_http_application_profile.go new file mode 100644 index 000000000..71ebd567c --- /dev/null +++ b/nsxt/resource_nsxt_policy_lb_http_application_profile.go @@ -0,0 +1,240 @@ +/* Copyright © 2020 VMware, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" + "github.com/vmware/vsphere-automation-sdk-go/runtime/data" + "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" +) + +var lBHttpProfileXForwardedForValues = []string{ + model.LBHttpProfile_X_FORWARDED_FOR_REPLACE, + model.LBHttpProfile_X_FORWARDED_FOR_INSERT, +} + +func resourceNsxtPolicyLBHttpApplicationProfile() *schema.Resource { + return &schema.Resource{ + Create: resourceNsxtPolicyLBHttpApplicationProfileCreate, + Read: resourceNsxtPolicyLBHttpApplicationProfileRead, + Update: resourceNsxtPolicyLBHttpApplicationProfileUpdate, + Delete: resourceNsxtPolicyLBHttpApplicationProfileDelete, + Importer: &schema.ResourceImporter{ + State: nsxtPolicyPathResourceImporter, + }, + + Schema: map[string]*schema.Schema{ + "nsx_id": getNsxIDSchema(), + "path": getPathSchema(), + "display_name": getDisplayNameSchema(), + "description": getDescriptionSchema(), + "revision": getRevisionSchema(), + "tag": getTagsSchema(), + "http_redirect_to": { + Type: schema.TypeString, + Description: "A URL that incoming requests for that virtual server can be temporarily redirected to, If a website is temporarily down or has moved", + Optional: true, + }, + "http_redirect_to_https": { + Type: schema.TypeBool, + Description: "A boolean flag which reflects whether the client will automatically be redirected to use SSL", + Optional: true, + Default: false, + }, + "idle_timeout": { + Type: schema.TypeInt, + Description: "Timeout in seconds to specify how long an HTTP application can remain idle", + Optional: true, + Default: 15, + ValidateFunc: validation.IntAtLeast(1), + }, + "request_body_size": { + Type: schema.TypeInt, + Description: "Maximum request body size in bytes (Unlimited if not specified)", + Optional: true, + }, + "request_header_size": { + Type: schema.TypeInt, + Description: "Maximum request header size in bytes. Requests with larger header size will be processed as best effort whereas a request with header below this specified size is guaranteed to be processed", + Optional: true, + Default: 1024, + ValidateFunc: validation.IntBetween(1, 65536), + }, + "response_buffering": { + Type: schema.TypeBool, + Optional: true, + Description: "A boolean flag indicating whether the response received by LB from the backend will be saved into the buffers", + Default: false, + }, + "response_header_size": { + Type: schema.TypeInt, + Description: "Maximum request header size in bytes. Requests with larger header size will be processed as best effort whereas a request with header below this specified size is guaranteed to be processed", + Optional: true, + Default: 4096, + ValidateFunc: validation.IntBetween(1, 65536), + }, + "response_timeout": { + Type: schema.TypeInt, + Description: "Number of seconds waiting for the server response before the connection is closed", + Optional: true, + Default: 60, + ValidateFunc: validation.IntAtLeast(1), + }, + "server_keep_alive": { + Type: schema.TypeBool, + Optional: true, + Description: "A boolean flag indicating whether the backend connection will be kept alive for client connection. If server_keep_alive is true, it means the backend connection will keep alive for the client connection. Every client connection is tied 1:1 with the corresponding server-side connection. If server_keep_alive is false, it means the backend connection won't keep alive for the client connection.", + Default: false, + }, + "x_forwarded_for": { + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice(lBHttpProfileXForwardedForValues, false), + Optional: true, + Description: "When X-Forwareded-For is configured, X-Forwarded-Proto and X-Forwarded-Port information is added automatically into request header", + }, + }, + } +} + +func resourceNsxtPolicyLBHttpApplicationProfileExists(id string, connector client.Connector, isGlobalManager bool) (bool, error) { + return resourceNsxtPolicyLBAppProfileExists(id, connector, isGlobalManager) +} + +func resourceNsxtPolicyLBHttpApplicationProfilePatch(d *schema.ResourceData, m interface{}, id string) error { + connector := getPolicyConnector(m) + converter := bindings.NewTypeConverter() + + displayName := d.Get("display_name").(string) + description := d.Get("description").(string) + tags := getPolicyTagsFromSchema(d) + httpRedirectTo := d.Get("http_redirect_to").(string) + httpRedirectToHTTPS := d.Get("http_redirect_to_https").(bool) + idleTimeout := int64(d.Get("idle_timeout").(int)) + requestBodySize := int64(d.Get("request_body_size").(int)) + requestHeaderSize := int64(d.Get("request_header_size").(int)) + responseBuffering := d.Get("response_buffering").(bool) + responseHeaderSize := int64(d.Get("response_header_size").(int)) + responseTimeout := int64(d.Get("response_timeout").(int)) + serverKeepAlive := d.Get("server_keep_alive").(bool) + xForwardedFor := d.Get("x_forwarded_for").(string) + resourceType := model.LBAppProfile_RESOURCE_TYPE_LBHTTPPROFILE + obj := model.LBHttpProfile{ + DisplayName: &displayName, + Description: &description, + Tags: tags, + HttpRedirectToHttps: &httpRedirectToHTTPS, + IdleTimeout: &idleTimeout, + RequestHeaderSize: &requestHeaderSize, + ResponseBuffering: &responseBuffering, + ResponseHeaderSize: &responseHeaderSize, + ResponseTimeout: &responseTimeout, + ServerKeepAlive: &serverKeepAlive, + ResourceType: resourceType, + } + if requestBodySize > 0 { + obj.RequestBodySize = &requestBodySize + } + if len(xForwardedFor) > 0 { + obj.XForwardedFor = &xForwardedFor + } + if len(httpRedirectTo) > 0 { + obj.HttpRedirectTo = &httpRedirectTo + } + + log.Printf("[INFO] Patching LBHttpProfile with ID %s", id) + dataValue, errs := converter.ConvertToVapi(obj, model.LBHttpProfileBindingType()) + if errs != nil { + return fmt.Errorf("Error converting LBHttpProfile %s", errs[0]) + } + + client := infra.NewLbAppProfilesClient(connector) + return client.Patch(id, dataValue.(*data.StructValue)) +} + +func resourceNsxtPolicyLBHttpApplicationProfileCreate(d *schema.ResourceData, m interface{}) error { + + // Initialize resource Id and verify this ID is not yet used + id, err := getOrGenerateID(d, m, resourceNsxtPolicyLBHttpApplicationProfileExists) + if err != nil { + return err + } + + err = resourceNsxtPolicyLBHttpApplicationProfilePatch(d, m, id) + if err != nil { + return handleCreateError("LBHttpProfile", id, err) + } + + d.SetId(id) + d.Set("nsx_id", id) + + return resourceNsxtPolicyLBHttpApplicationProfileRead(d, m) +} + +func resourceNsxtPolicyLBHttpApplicationProfileRead(d *schema.ResourceData, m interface{}) error { + connector := getPolicyConnector(m) + converter := bindings.NewTypeConverter() + + id := d.Id() + if id == "" { + return fmt.Errorf("Error obtaining LBHttpProfile ID") + } + + client := infra.NewLbAppProfilesClient(connector) + obj, err := client.Get(id) + if err != nil { + return handleReadError(d, "LBHttpProfile", id, err) + } + + baseObj, errs := converter.ConvertToGolang(obj, model.LBHttpProfileBindingType()) + if len(errs) > 0 { + return fmt.Errorf("LBAppProfile with id %s is not of type LBHttpProfile %s", id, errs[0]) + } + lbHTTPProfile := baseObj.(model.LBHttpProfile) + + d.Set("display_name", lbHTTPProfile.DisplayName) + d.Set("description", lbHTTPProfile.Description) + setPolicyTagsInSchema(d, lbHTTPProfile.Tags) + d.Set("nsx_id", id) + d.Set("path", lbHTTPProfile.Path) + d.Set("revision", lbHTTPProfile.Revision) + + d.Set("http_redirect_to", lbHTTPProfile.HttpRedirectTo) + d.Set("http_redirect_to_https", lbHTTPProfile.HttpRedirectToHttps) + d.Set("idle_timeout", lbHTTPProfile.IdleTimeout) + d.Set("request_body_size", lbHTTPProfile.RequestBodySize) + d.Set("request_header_size", lbHTTPProfile.RequestHeaderSize) + d.Set("response_buffering", lbHTTPProfile.ResponseBuffering) + d.Set("response_header_size", lbHTTPProfile.ResponseHeaderSize) + d.Set("response_timeout", lbHTTPProfile.ResponseTimeout) + d.Set("server_keep_alive", lbHTTPProfile.ServerKeepAlive) + d.Set("x_forwarded_for", lbHTTPProfile.XForwardedFor) + + return nil +} + +func resourceNsxtPolicyLBHttpApplicationProfileUpdate(d *schema.ResourceData, m interface{}) error { + + id := d.Id() + if id == "" { + return fmt.Errorf("Error obtaining LBHttpProfile ID") + } + + err := resourceNsxtPolicyLBHttpApplicationProfilePatch(d, m, id) + if err != nil { + return handleUpdateError("LBHttpProfile", id, err) + } + + return resourceNsxtPolicyLBHttpApplicationProfileRead(d, m) +} + +func resourceNsxtPolicyLBHttpApplicationProfileDelete(d *schema.ResourceData, m interface{}) error { + return resourceNsxtPolicyLBAppProfileDelete(d, m) +} diff --git a/nsxt/resource_nsxt_policy_lb_http_application_profile_test.go b/nsxt/resource_nsxt_policy_lb_http_application_profile_test.go new file mode 100644 index 000000000..1ac49f5fa --- /dev/null +++ b/nsxt/resource_nsxt_policy_lb_http_application_profile_test.go @@ -0,0 +1,221 @@ +/* Copyright © 2020 VMware, Inc. All Rights Reserved. + SPDX-License-Identifier: MPL-2.0 */ + +package nsxt + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +var accTestPolicyLBHttpApplicationProfileCreateAttributes = map[string]string{ + "display_name": getAccTestResourceName(), + "description": "terraform created", + "http_redirect_to": "http://www.test-create.com", + "http_redirect_to_https": "false", + "idle_timeout": "15", + "request_body_size": "256", + "request_header_size": "1024", + "response_buffering": "true", + "response_header_size": "2048", + "response_timeout": "20", + "server_keep_alive": "true", + "x_forwarded_for": "REPLACE", +} + +var accTestPolicyLBHttpApplicationProfileUpdateAttributes = map[string]string{ + "display_name": getAccTestResourceName(), + "description": "terraform updated", + "http_redirect_to": "http://www.test-update.com", + "http_redirect_to_https": "false", + "idle_timeout": "20", + "request_body_size": "512", + "request_header_size": "2048", + "response_buffering": "false", + "response_header_size": "4096", + "response_timeout": "10", + "server_keep_alive": "false", + "x_forwarded_for": "INSERT", +} + +func TestAccResourceNsxtPolicyLBHttpApplicationProfile_basic(t *testing.T) { + testResourceName := "nsxt_policy_lb_http_application_profile.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyLBHttpApplicationProfileCheckDestroy(state, accTestPolicyLBHttpApplicationProfileUpdateAttributes["display_name"]) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyLBHttpApplicationProfileTemplate(true), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyLBHttpApplicationProfileExists(accTestPolicyLBHttpApplicationProfileCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyLBHttpApplicationProfileCreateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyLBHttpApplicationProfileCreateAttributes["description"]), + resource.TestCheckResourceAttr(testResourceName, "http_redirect_to", accTestPolicyLBHttpApplicationProfileCreateAttributes["http_redirect_to"]), + resource.TestCheckResourceAttr(testResourceName, "http_redirect_to_https", accTestPolicyLBHttpApplicationProfileCreateAttributes["http_redirect_to_https"]), + resource.TestCheckResourceAttr(testResourceName, "idle_timeout", accTestPolicyLBHttpApplicationProfileCreateAttributes["idle_timeout"]), + resource.TestCheckResourceAttr(testResourceName, "request_body_size", accTestPolicyLBHttpApplicationProfileCreateAttributes["request_body_size"]), + resource.TestCheckResourceAttr(testResourceName, "request_header_size", accTestPolicyLBHttpApplicationProfileCreateAttributes["request_header_size"]), + resource.TestCheckResourceAttr(testResourceName, "response_buffering", accTestPolicyLBHttpApplicationProfileCreateAttributes["response_buffering"]), + resource.TestCheckResourceAttr(testResourceName, "response_header_size", accTestPolicyLBHttpApplicationProfileCreateAttributes["response_header_size"]), + resource.TestCheckResourceAttr(testResourceName, "response_timeout", accTestPolicyLBHttpApplicationProfileCreateAttributes["response_timeout"]), + resource.TestCheckResourceAttr(testResourceName, "server_keep_alive", accTestPolicyLBHttpApplicationProfileCreateAttributes["server_keep_alive"]), + resource.TestCheckResourceAttr(testResourceName, "x_forwarded_for", accTestPolicyLBHttpApplicationProfileCreateAttributes["x_forwarded_for"]), + + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + { + Config: testAccNsxtPolicyLBHttpApplicationProfileTemplate(false), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyLBHttpApplicationProfileExists(accTestPolicyLBHttpApplicationProfileUpdateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyLBHttpApplicationProfileUpdateAttributes["display_name"]), + resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyLBHttpApplicationProfileUpdateAttributes["description"]), + resource.TestCheckResourceAttr(testResourceName, "http_redirect_to", accTestPolicyLBHttpApplicationProfileUpdateAttributes["http_redirect_to"]), + resource.TestCheckResourceAttr(testResourceName, "http_redirect_to_https", accTestPolicyLBHttpApplicationProfileUpdateAttributes["http_redirect_to_https"]), + resource.TestCheckResourceAttr(testResourceName, "idle_timeout", accTestPolicyLBHttpApplicationProfileUpdateAttributes["idle_timeout"]), + resource.TestCheckResourceAttr(testResourceName, "request_body_size", accTestPolicyLBHttpApplicationProfileUpdateAttributes["request_body_size"]), + resource.TestCheckResourceAttr(testResourceName, "request_header_size", accTestPolicyLBHttpApplicationProfileUpdateAttributes["request_header_size"]), + resource.TestCheckResourceAttr(testResourceName, "response_buffering", accTestPolicyLBHttpApplicationProfileUpdateAttributes["response_buffering"]), + resource.TestCheckResourceAttr(testResourceName, "response_header_size", accTestPolicyLBHttpApplicationProfileUpdateAttributes["response_header_size"]), + resource.TestCheckResourceAttr(testResourceName, "response_timeout", accTestPolicyLBHttpApplicationProfileUpdateAttributes["response_timeout"]), + resource.TestCheckResourceAttr(testResourceName, "server_keep_alive", accTestPolicyLBHttpApplicationProfileUpdateAttributes["server_keep_alive"]), + resource.TestCheckResourceAttr(testResourceName, "x_forwarded_for", accTestPolicyLBHttpApplicationProfileUpdateAttributes["x_forwarded_for"]), + + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), + ), + }, + { + Config: testAccNsxtPolicyLBHttpApplicationProfileMinimalistic(), + Check: resource.ComposeTestCheckFunc( + testAccNsxtPolicyLBHttpApplicationProfileExists(accTestPolicyLBHttpApplicationProfileCreateAttributes["display_name"], testResourceName), + resource.TestCheckResourceAttr(testResourceName, "description", ""), + resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), + resource.TestCheckResourceAttrSet(testResourceName, "path"), + resource.TestCheckResourceAttrSet(testResourceName, "revision"), + resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), + ), + }, + }, + }) +} + +func TestAccResourceNsxtPolicyLBHttpApplicationProfile_importBasic(t *testing.T) { + name := getAccTestResourceName() + testResourceName := "nsxt_policy_lb_http_application_profile.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccOnlyLocalManager(t) }, + Providers: testAccProviders, + CheckDestroy: func(state *terraform.State) error { + return testAccNsxtPolicyLBHttpApplicationProfileCheckDestroy(state, name) + }, + Steps: []resource.TestStep{ + { + Config: testAccNsxtPolicyLBHttpApplicationProfileMinimalistic(), + }, + { + ResourceName: testResourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccNsxtPolicyLBHttpApplicationProfileExists(displayName string, resourceName string) resource.TestCheckFunc { + return func(state *terraform.State) error { + + connector := getPolicyConnector(testAccProvider.Meta().(nsxtClients)) + + rs, ok := state.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Policy LBHttpProfile resource %s not found in resources", resourceName) + } + + resourceID := rs.Primary.ID + if resourceID == "" { + return fmt.Errorf("Policy LBHttpProfile resource ID not set in resources") + } + + exists, err := resourceNsxtPolicyLBHttpApplicationProfileExists(resourceID, connector, testAccIsGlobalManager()) + if err != nil { + return err + } + if !exists { + return fmt.Errorf("Policy LBHttpProfile %s does not exist", resourceID) + } + + return nil + } +} + +func testAccNsxtPolicyLBHttpApplicationProfileCheckDestroy(state *terraform.State, displayName string) error { + connector := getPolicyConnector(testAccProvider.Meta().(nsxtClients)) + for _, rs := range state.RootModule().Resources { + + if rs.Type != "nsxt_policy_lb_http_application_profile" { + continue + } + + resourceID := rs.Primary.Attributes["id"] + exists, err := resourceNsxtPolicyLBHttpApplicationProfileExists(resourceID, connector, testAccIsGlobalManager()) + if err == nil { + return err + } + + if exists { + return fmt.Errorf("Policy LBHttpProfile %s still exists", displayName) + } + } + return nil +} + +func testAccNsxtPolicyLBHttpApplicationProfileTemplate(createFlow bool) string { + var attrMap map[string]string + if createFlow { + attrMap = accTestPolicyLBHttpApplicationProfileCreateAttributes + } else { + attrMap = accTestPolicyLBHttpApplicationProfileUpdateAttributes + } + return fmt.Sprintf(` +resource "nsxt_policy_lb_http_application_profile" "test" { + display_name = "%s" + description = "%s" + http_redirect_to = "%s" + http_redirect_to_https = %s + idle_timeout = %s + request_body_size = %s + request_header_size = %s + response_buffering = %s + response_header_size = %s + response_timeout = %s + server_keep_alive = %s + x_forwarded_for = "%s" + + tag { + scope = "scope1" + tag = "tag1" + } +}`, attrMap["display_name"], attrMap["description"], attrMap["http_redirect_to"], attrMap["http_redirect_to_https"], attrMap["idle_timeout"], attrMap["request_body_size"], attrMap["request_header_size"], attrMap["response_buffering"], attrMap["response_header_size"], attrMap["response_timeout"], attrMap["server_keep_alive"], attrMap["x_forwarded_for"]) +} + +func testAccNsxtPolicyLBHttpApplicationProfileMinimalistic() string { + return fmt.Sprintf(` +resource "nsxt_policy_lb_http_application_profile" "test" { + display_name = "%s" + +}`, accTestPolicyLBHttpApplicationProfileUpdateAttributes["display_name"]) +} diff --git a/website/docs/r/policy_lb_http_application_profile.html.markdown b/website/docs/r/policy_lb_http_application_profile.html.markdown new file mode 100644 index 000000000..0bd80d33e --- /dev/null +++ b/website/docs/r/policy_lb_http_application_profile.html.markdown @@ -0,0 +1,72 @@ +--- +subcategory: "Load Balancer" +layout: "nsxt" +page_title: "NSXT: nsxt_policy_lb_http_application_profile" +description: A resource to configure a LBHttpApplicationProfile. +--- + +# nsxt_policy_lb_http_application_profile + +This resource provides a method for the management of a LBHttpApplicationProfile. + +This resource is applicable to NSX Policy Manager. + +## Example Usage + +```hcl +resource "nsxt_policy_lb_http_application_profile" "test" { + display_name = "test" + description = "Terraform provisioned LBHttpProfile" + http_redirect_to = "http://www.google.com" + http_redirect_to_https = false + idle_timeout = 15 + request_body_size = 256 + request_header_size = 1024 + response_buffering = true + response_header_size = 4096 + response_timeout = 100 + server_keep_alive = true + x_forwarded_for = "REPLACE" + +} +``` + +## Argument Reference + +The following arguments are supported: + +* `display_name` - (Required) Display name of the resource. +* `description` - (Optional) Description of the resource. +* `tag` - (Optional) A list of scope + tag pairs to associate with this resource. +* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. +* `http_redirect_to` - (Optional) If a website is temporarily down or has moved, incoming requests for that virtual server can be temporarily redirected to a URL. +* `http_redirect_to_https` - (Optional) A boolean flag which reflects whether the client will automatically be redirected to use SSL. +* `idle_timeout` - (Optional) Timeout in seconds to specify how long an HTTP application can remain idle. +* `request_body_size` - (Optional) Maximum request body size in bytes (Unlimited if not specified). +* `request_header_size` - (Optional) Maximum request header size in bytes. Requests with larger header size will be processed as best effort whereas a request with header below this specified size is guaranteed to be processed. +* `response_buffering` - (Optional) A boolean flag indicating whether the response received by LB from the backend will be saved into the buffers. When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. When buffering is enabled, LB receives a response from the backend server as soon as possible, saving it into the buffers. +* `response_header_size` - (Optional) Maximum request header size in bytes. Requests with larger header size will be processed as best effort whereas a request with header below this specified size is guaranteed to be processed. +* `response_timeout` - (Optional) Number of seconds waiting for the server response before the connection is closed. +* `server_keep_alive` - (Optional) A boolean flag indicating whether the backend connection will be kept alive for client connection. If server_keep_alive is true, it means the backend connection will keep alive for the client connection. Every client connection is tied 1:1 with the corresponding server-side connection. If server_keep_alive is false, it means the backend connection won't keep alive for the client connection. +* `x_forwarded_for` - (Optional) When X-Forwareded-For is configured, X-Forwarded-Proto and X-Forwarded-Port information is added automatically to the request header. Possible values are:`INSERT`, `REPLACE` + + +## Attributes Reference + +In addition to arguments listed above, the following attributes are exported: + +* `id` - ID of the resource. +* `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. +* `path` - The NSX path of the policy resource. + +## Importing + +An existing object can be [imported][docs-import] into this resource, via the following command: + +[docs-import]: https://www.terraform.io/cli/import + +``` +terraform import nsxt_policy_lb_http_application_profile.test UUID +``` + +The above command imports LBHttpProfile named `test` with the NSX ID `UUID`.