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

Issue 1024, 1009 #1038

Open
wants to merge 5 commits into
base: master
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
2 changes: 1 addition & 1 deletion bigip/resource_bigip_ltm_datagroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func resourceBigipLtmDataGroupRead(ctx context.Context, d *schema.ResourceData,
name := d.Id()
log.Printf("[DEBUG] Retrieving Data Group List %s", name)
datagroup, err := client.GetInternalDataGroup(name)
if err != nil {
if err != nil && !strings.Contains(err.Error(), "not found") {
return diag.FromErr(fmt.Errorf("Error retrieving Data Group List %s: %v ", name, err))
}

Expand Down
43 changes: 43 additions & 0 deletions bigip/resource_bigip_ltm_datagroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var TestDatagroupStringResource = `
}
}`

var TestExternalDatagroupResource = `
resource "bigip_ltm_datagroup" "test-datagroup-string" {
name = "` + TestDatagroupName + `"
type = "string"
internal = false
records_src = "foo.bars"

}`

var TestDatagroupIpResource = `
resource "bigip_ltm_datagroup" "test-datagroup-ip" {
name = "` + TestDatagroupName + `"
Expand Down Expand Up @@ -73,6 +82,24 @@ func TestAccBigipLtmDataGroup_Create_TypeString(t *testing.T) {
},
})
}

func TestAccBigipLtmDataGroup_Create_External(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckDataGroupDestroyed,
Steps: []resource.TestStep{
{
Config: TestExternalDatagroupResource,
Check: resource.ComposeTestCheckFunc(
testCheckExternalDataGroupExists(TestDatagroupName),
),
},
},
})
}
func TestAccBigipLtmDataGroup_Create_TypeIp(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -186,6 +213,22 @@ func testCheckDataGroupExists(name string) resource.TestCheckFunc {
}
}

func testCheckExternalDataGroupExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
datagroup, err := client.GetExternalDataGroup(name)
if err != nil {
return fmt.Errorf("Error while fetching Data Group: %v ", err)

}
datagroupName := datagroup.FullPath
if datagroupName != name {
return fmt.Errorf("Data Group name does not match. Expecting %s got %s ", name, datagroupName)
}
return nil
}
}

func testCheckDataGroupDestroyed(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)

Expand Down
13 changes: 9 additions & 4 deletions bigip/resource_bigip_ltm_profile_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func resourceBigipLtmProfileHttp() *schema.Resource {
Description: "Specifies a passphrase for the cookie encryption. Note: Since it's a sensitive entity idempotency will fail for it in the update call.",
},
"fallback_host": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
// Computed: true,
Description: "Specifies an HTTP fallback host. HTTP redirection allows you to redirect HTTP traffic to another protocol identifier, host name, port number, or URI path.",
},
"fallback_status_codes": {
Expand Down Expand Up @@ -468,7 +468,12 @@ func getHttpProfileConfig(d *schema.ResourceData, config *bigip.HttpProfile) *bi
config.Description = d.Get("description").(string)
config.EncryptCookieSecret = d.Get("encrypt_cookie_secret").(string)
config.EncryptCookies = setToStringSlice(d.Get("encrypt_cookies").(*schema.Set))
config.FallbackHost = d.Get("fallback_host").(string)
if _, ok := d.GetOk("fallback_host"); ok {
config.FallbackHost = d.Get("fallback_host").(string)
} else {
config.FallbackHost = ""
}

config.FallbackStatusCodes = setToStringSlice(d.Get("fallback_status_codes").(*schema.Set))
config.HeaderErase = d.Get("head_erase").(string)
config.HeaderInsert = d.Get("head_insert").(string)
Expand Down
63 changes: 41 additions & 22 deletions bigip/resource_bigip_ltm_profile_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ var resHttpName = "bigip_ltm_profile_http"

var TestHttpResource = `
resource "bigip_ltm_profile_http" "test-http" {
name = "/Common/test-http"
defaults_from = "/Common/http"
description = "some http"
fallback_host = "titanic"
fallback_status_codes = ["400","500","300"]
name = "/Common/test-http"
defaults_from = "/Common/http"
description = "some http"
fallback_host = "titanic"
fallback_status_codes = ["400", "500", "300"]
}
`

Expand Down Expand Up @@ -92,7 +92,7 @@ func TestAccBigipLtmProfileHttpUpdateServerAgent(t *testing.T) {
CheckDestroy: testCheckHttpsDestroyed,
Steps: []resource.TestStep{
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName, "http-profile-test"),
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
Expand All @@ -109,7 +109,7 @@ func TestAccBigipLtmProfileHttpUpdateServerAgent(t *testing.T) {
),
},
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName, "http-profile-test"),
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
Expand All @@ -121,38 +121,47 @@ func TestAccBigipLtmProfileHttpUpdateServerAgent(t *testing.T) {
})
}

func TestAccBigipLtmProfileHttpUpdateFallbackhost(t *testing.T) {
func TestAccBigipLtmProfileHttpUpdateFallbackHost(t *testing.T) {
t.Parallel()
var instName = "test-http-Update-FallbackHost"
var instFullName = fmt.Sprintf("/%s/%s", TestPartition, instName)
resFullName := fmt.Sprintf("%s.%s", resHttpName, instName)
var instName = "test-http-Update-fallbackhost"
var TestHttpName = fmt.Sprintf("/%s/%s", TestPartition, instName)
resFullName := fmt.Sprintf("%s.%s", resHttpName, "http-profile-test")
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckHttpsDestroyed,
Providers: testAccProviders,
// CheckDestroy: testCheckHttpsDestroyed,
Steps: []resource.TestStep{
{
Config: testaccbigipltmprofilehttpUpdateParam(instName, ""),
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(instFullName),
resource.TestCheckResourceAttr(resFullName, "name", instFullName),
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
),
},
{
Config: testaccbigipltmprofilehttpUpdateParam(instName, "fallback_host"),
Config: testaccbigipltmprofilehttpUpdateFallbackHost(TestPartition, TestHttpName, "http-profile-test"),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(instFullName),
resource.TestCheckResourceAttr(resFullName, "name", instFullName),
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
resource.TestCheckResourceAttr(resFullName, "fallback_host", "https://www.google.de"),
),
},
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
resource.TestCheckResourceAttr(resFullName, "fallback_host", "titanic"),
),
},
},
})
}

func TestAccBigipLtmProfileHttpUpdateBasicAuthRealm(t *testing.T) {
t.Parallel()
var instName = "test-http-Update-BasicAuthRealm"
Expand Down Expand Up @@ -525,13 +534,13 @@ func testCheckHttpsDestroyed(s *terraform.State) error {
return nil
}

func testaccbigipltmprofilehttpDefaultConfig(partition, profileName, resourceName string) string {
func testaccbigipltmprofilehttpDefaultConfig(partition, profileName string) string {
return fmt.Sprintf(`
resource "bigip_ltm_profile_http" "%[3]s" {
name = "%[2]s"
defaults_from = "/%[1]s/http"
}
`, partition, profileName, resourceName)
`, partition, profileName, "http-profile-test")
}

func testaccbigipltmprofilehttpUpdateServeragentConfig(partition, profileName, resourceName string) string {
Expand All @@ -544,6 +553,16 @@ resource "bigip_ltm_profile_http" "%[3]s" {
`, partition, profileName, resourceName)
}

func testaccbigipltmprofilehttpUpdateFallbackHost(partition, profileName, resourceName string) string {
return fmt.Sprintf(`
resource "bigip_ltm_profile_http" "%[3]s" {
name = "%[2]s"
defaults_from = "/%[1]s/http"
fallback_host = "https://www.google.de"
}
`, partition, profileName, resourceName)
}

func testaccBigipLtmHttpProfileImportConfig() string {
return fmt.Sprintf(`
resource "bigip_ltm_profile_http" "test-http" {
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/f5devcentral/go-bigip/ltm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading