Skip to content

Commit

Permalink
Fixed issue 834, 836
Browse files Browse the repository at this point in the history
  • Loading branch information
ramaniprateek committed Nov 15, 2023
1 parent 0e33fc2 commit 8fa9718
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
13 changes: 7 additions & 6 deletions bigip/resource_bigip_ltm_profile_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,31 @@ func resourceBigipLtmProfileHttp() *schema.Resource {
"http_strict_transport_security": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"include_subdomains": {
Type: schema.TypeString,
Optional: true,
Default: "enabled",
Computed: true,
Description: "Specifies whether to include the includeSubdomains directive in the HSTS header.",
},
"maximum_age": {
Type: schema.TypeInt,
Optional: true,
Default: 16070400,
Computed: true,
Description: "Specifies the maximum age to assume the connection should remain secure.",
},
"mode": {
Type: schema.TypeString,
Optional: true,
Default: "disabled",
Computed: true,
Description: "Specifies whether to include the HSTS response header.",
},
"preload": {
Type: schema.TypeString,
Optional: true,
Default: "disabled",
Computed: true,
Description: "Specifies whether to include the preload directive in the HSTS header.",
},
},
Expand Down Expand Up @@ -490,8 +491,8 @@ func getHttpProfileConfig(d *schema.ResourceData, config *bigip.HttpProfile) *bi

for _, r := range p.(*schema.Set).List() {
config.Hsts.IncludeSubdomains = r.(map[string]interface{})["include_subdomains"].(string)
config.Hsts.Mode = r.(map[string]interface{})["preload"].(string)
config.Hsts.Preload = r.(map[string]interface{})["mode"].(string)
config.Hsts.Mode = r.(map[string]interface{})["mode"].(string)
config.Hsts.Preload = r.(map[string]interface{})["preload"].(string)
config.Hsts.MaximumAge = r.(map[string]interface{})["maximum_age"].(int)
}

Expand Down
30 changes: 27 additions & 3 deletions bigip/resource_bigip_ltm_profile_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package bigip

import (
"fmt"
"regexp"
"testing"

bigip "github.com/f5devcentral/go-bigip"

Check failure on line 10 in bigip/resource_bigip_ltm_profile_http_test.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"regexp"
"strings"
"testing"
)

var TestHttpName = fmt.Sprintf("/%s/test-http", TestPartition)
Expand Down Expand Up @@ -107,6 +107,15 @@ func TestAccBigipLtmProfileHttpUpdateServerAgent(t *testing.T) {
resource.TestCheckResourceAttr(resFullName, "server_agent_name", "myBIG-IP"),
),
},
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName, "http-profile-test"),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
resource.TestCheckResourceAttr(resFullName, "server_agent_name", "myBIG-IP"),
),
},
},
})
}
Expand Down Expand Up @@ -419,6 +428,18 @@ func TestAccBigipLtmProfileHttpUpdateHSTS(t *testing.T) {
resource.TestCheckResourceAttr(resFullName, "http_strict_transport_security.0.maximum_age", "80"),
),
},
{
Config: testaccbigipltmprofilehttpUpdateParam(instName, ""),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(instFullName),
resource.TestCheckResourceAttr(resFullName, "name", instFullName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
resource.TestCheckResourceAttr(resFullName, "http_strict_transport_security.0.include_subdomains", "disabled"),
resource.TestCheckResourceAttr(resFullName, "http_strict_transport_security.0.preload", "enabled"),
resource.TestCheckResourceAttr(resFullName, "http_strict_transport_security.0.mode", "enabled"),
resource.TestCheckResourceAttr(resFullName, "http_strict_transport_security.0.maximum_age", "80"),
),
},
},
})
}
Expand Down Expand Up @@ -470,6 +491,9 @@ func testCheckHttpsDestroyed(s *terraform.State) error {
name := rs.Primary.ID
http, err := client.GetHttpProfile(name)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return nil
}
return err
}
if http != nil {
Expand Down
10 changes: 5 additions & 5 deletions docs/resources/bigip_ltm_profile_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ resource "bigip_ltm_profile_http" "sanjose-http" {

* `xff_alternative_names` - (Optional) Specifies alternative XFF headers instead of the default X-forwarded-for header.

* `server_agent_name` - (Optional) Specifies the value of the Server header in responses that the BIG-IP itself generates. The default is BigIP. If no string is specified, then default value will be added to such responses. In order to remove it, "none" string is to be passed.
* `server_agent_name` - (Optional) Specifies the value of the Server header in responses that the BIG-IP itself generates. The default is BigIP. In order to remove it, "none" string is to be passed. If server_agent_name is commented (or not passed) during the update call, then no changes would be applied and previous value will persist. If "default-value" is specified in Update for server_agent_name, then default value will be added by BigIP.

* `enforcement` -See [Enforcement](#enforcement) below for more details.

Expand All @@ -96,13 +96,13 @@ The `enforcement` block supports the following:

The `http_strict_transport_security` block supports the following:

* `include_subdomains` - (Optional , `string`) Specifies whether to include the includeSubdomains directive in the HSTS header. The default is enabled. If no string is specified, then default value will be assigned.
* `include_subdomains` - (Optional , `string`) The Include Subdomains setting applies the HSTS policy to the HSTS host and its subdomains. The default is enabled. If no string is specified during Create, then default value will be assigned by BigIp. If include_subdomains is commented (or not passed) during the update call, then no changes would be applied and previous value will persist. If "default-value" is specified in Update for include_subdomains, then default value will be added by BigIP.

* `preload` - (Optional , `string`) Specifies whether to include the preload directive in the HSTS header. The default is disabled. If no string is specified, then default value will be assigned.
* `preload` - (Optional , `string`) An HSTS preload list is a list of domains built into a web browser. When you enable the Preload setting, the domain for the web site that this HTTP profile is associated with is submitted for inclusion in the browser's preload list. The default is disabled. If no string is specified during Create, then default value will be assigned by BigIp. If preload is commented (or not passed) during the update call, then no changes would be applied and previous value will persist. If "default-value" is specified in Update for preload, then default value will be added by BigIP.

* `mode` - (Optional , `string`) Specifies whether to include the HSTS response header. The default is disabled.If no string is specified, then default value will be assigned.
* `mode` - (Optional , `string`) The Mode setting enables and disables HSTS functionality within the HTTP profile. The default is disabled. If no string is specified during Create, then default value will be assigned by BigIp. If mode is commented (or not passed) during the update call, then no changes would be applied and previous value will persist. If "default-value" is specified in Update for mode, then default value will be added by BigIP.

* `maximum_age` - (Optional , `int`) Specifies the maximum age to assume the connection should remain secure. The default is 16070400 seconds. If no value is specified, then default value will be assigned.
* `maximum_age` - (Optional , `int`) The Maximum Age value specifies the length of time, in seconds, that HSTS functionality requests that clients only use HTTPS to connect to the current host and any subdomains of the current host's domain name. The default is 16070400 seconds. If no value is specified during Create, then default value will be assigned by BigIp. If maximum_age is commented (or not passed) during the update call, then no changes would be applied and previous value will persist. In order to put default value , we need to pass 16070400 explicitly.


## Import
Expand Down

0 comments on commit 8fa9718

Please sign in to comment.