Skip to content

Commit

Permalink
Added fix for 1024, 1009
Browse files Browse the repository at this point in the history
  • Loading branch information
ramaniprateek committed Dec 12, 2024
1 parent 825bdc0 commit b6d1594
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 6 deletions.
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
51 changes: 51 additions & 0 deletions bigip/resource_bigip_ltm_profile_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,47 @@ func TestAccBigipLtmProfileHttpUpdateServerAgent(t *testing.T) {
})
}

func TestAccBigipLtmProfileHttpUpdateFallbackHost(t *testing.T) {
t.Parallel()
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,
Steps: []resource.TestStep{
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName, "http-profile-test"),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
),
},
{
Config: testaccbigipltmprofilehttpUpdateFallbackHost(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, "fallback_host", "https://www.google.de"),
),
},
{
Config: testaccbigipltmprofilehttpDefaultConfig(TestPartition, TestHttpName, "http-profile-test"),
Check: resource.ComposeTestCheckFunc(
testCheckhttpExists(TestHttpName),
resource.TestCheckResourceAttr(resFullName, "name", TestHttpName),
resource.TestCheckResourceAttr(resFullName, "defaults_from", "/Common/http"),
),
},
},
})
}

func TestAccBigipLtmProfileHttpUpdateFallbackhost(t *testing.T) {
t.Parallel()
var instName = "test-http-Update-FallbackHost"
Expand Down Expand Up @@ -544,6 +585,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.

0 comments on commit b6d1594

Please sign in to comment.