Skip to content

Commit

Permalink
adding api retries/token timeout/vendor sync
Browse files Browse the repository at this point in the history
  • Loading branch information
RavinderReddyF5 committed Jan 3, 2024
1 parent 76ef99e commit 57a0a37
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 24 deletions.
26 changes: 26 additions & 0 deletions bigip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"reflect"
"regexp"
"strings"
"time"

bigip "github.com/f5devcentral/go-bigip"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -85,6 +86,24 @@ func Provider() *schema.Provider {
Description: "Login reference for token authentication (see BIG-IP REST docs for details)",
DefaultFunc: schema.EnvDefaultFunc("BIGIP_LOGIN_REF", "tmos"),
},
"api_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "A timeout for AS3 requests, represented as a number of seconds. Default: 60",
DefaultFunc: schema.EnvDefaultFunc("API_TIMEOUT", 60),
},
"token_timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "A lifespan to request for the AS3 auth token, represented as a number of seconds. Default: 1200",
DefaultFunc: schema.EnvDefaultFunc("TOKEN_TIMEOUT", 1200),
},
"api_retries": {
Type: schema.TypeInt,
Optional: true,
Description: "Amount of times to retry AS3 API requests. Default: 10.",
DefaultFunc: schema.EnvDefaultFunc("API_RETRIES", 10),
},
},
DataSourcesMap: map[string]*schema.Resource{
"bigip_ltm_datagroup": dataSourceBigipLtmDataGroup(),
Expand Down Expand Up @@ -185,13 +204,20 @@ func Provider() *schema.Provider {
}

func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, diag.Diagnostics) {
configOptions := &bigip.ConfigOptions{
APICallTimeout: time.Duration(d.Get("api_timeout").(int)) * time.Second,
TokenTimeout: time.Duration(d.Get("token_timeout").(int)) * time.Second,
APICallRetries: d.Get("api_retries").(int),
}

config := &bigip.Config{
Address: d.Get("address").(string),
Port: d.Get("port").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
Token: d.Get("token_value").(string),
CertVerifyDisable: d.Get("validate_certs_disable").(bool),
ConfigOptions: configOptions,
}
if d.Get("token_auth").(bool) {
config.LoginReference = d.Get("login_ref").(string)
Expand Down
26 changes: 13 additions & 13 deletions bigip/resource_bigip_ltm_profile_httpcompress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ var TestHttpcompressName = fmt.Sprintf("/%s/test-httpcompress", TestPartition)

var TestHttpcompressResource = `
resource "bigip_ltm_profile_httpcompress" "test-httpcompress" {
name = "/Common/test-httpcompress"
defaults_from = "/Common/httpcompression"
uri_exclude = ["f5.com"]
uri_include = ["cisco.com"]
content_type_include = ["nicecontent.com"]
content_type_exclude = ["nicecontentexclude.com"]
}
name = "/Common/test-httpcompress"
defaults_from = "/Common/httpcompression"
uri_exclude = ["f5.com"]
uri_include = ["cisco.com"]
content_type_include = ["nicecontent.com"]
content_type_exclude = ["nicecontentexclude.com"]
}
`

func TestAccBigipLtmProfileHttpcompress_create(t *testing.T) {
Expand All @@ -39,7 +39,7 @@ func TestAccBigipLtmProfileHttpcompress_create(t *testing.T) {
{
Config: TestHttpcompressResource,
Check: resource.ComposeTestCheckFunc(
testCheckHttpcompressExists(TestHttpcompressName, true),
testCheckHttpcompressExists("/Common/test-httpcompress", true),
resource.TestCheckResourceAttr("bigip_ltm_profile_httpcompress.test-httpcompress", "name", "/Common/test-httpcompress"),
resource.TestCheckResourceAttr("bigip_ltm_profile_httpcompress.test-httpcompress", "defaults_from", "/Common/httpcompression"),
resource.TestCheckTypeSetElemAttr("bigip_ltm_profile_httpcompress.test-httpcompress", "uri_exclude.*", "f5.com"),
Expand Down Expand Up @@ -146,7 +146,7 @@ func testCheckHttpcompressExists(name string, exists bool) resource.TestCheckFun
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
p, err := client.GetHttpcompress(name)
if err != nil {
if err != nil && exists {
return err
}
if exists && p == nil {
Expand All @@ -168,10 +168,10 @@ func testCheckHttpcompresssDestroyed(s *terraform.State) error {
}

name := rs.Primary.ID
httpcompress, err := client.GetHttpcompress(name)
if err != nil {
return err
}
httpcompress, _ := client.GetHttpcompress(name)
// if err != nil {
// return err
// }
if httpcompress != nil {
return fmt.Errorf("httpcompress %s not destroyed. ", name)
}
Expand Down
6 changes: 5 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This provider uses the iControlREST API. All the resources are validated with Bi
~> **NOTE** For AWAF resources, F5 BIG-IP version should be > v16.x , and ASM need to be provisioned.

## Example Usage

```hcl
variable hostname {}
variable username {}
Expand Down Expand Up @@ -45,11 +46,14 @@ provider "bigip" {
- `password` - (type `string`) BIG-IP Password for authentication. Can be set via the `BIGIP_PASSWORD` environment variable.
- `token_auth` - (Optional, Default `true`) Enable to use token authentication. Can be set via the `BIGIP_TOKEN_AUTH` environment variable.
- `token_value` - (Optional) A token generated outside the provider, in place of password
- `api_timeout` - (Optional, type `int`) A timeout for AS3 requests, represented as a number of seconds.
- `token_timeout` - (Optional, type `int`) A lifespan to request for the AS3 auth token, represented as a number of seconds.
- `api_retries` - (Optional, type `int`) Amount of times to retry AS3 API requests.
- `login_ref` - (Optional,Default `tmos`) Login reference for token authentication (see BIG-IP REST docs for details). May be set via the `BIGIP_LOGIN_REF` environment variable.
- `port` - (Optional) Management Port to connect to BIG-IP,this is mainly required if we have single nic BIG-IP in AWS/Azure/GCP (or) Management port other than `443`. Can be set via `BIGIP_PORT` environment variable.
- `validate_certs_disable` - (Optional, Default `true`) If set to true, Disables TLS certificate check on BIG-IP. Can be set via the `BIGIP_VERIFY_CERT_DISABLE` environment variable.
- `trusted_cert_path` - (type `string`) Provides Certificate Path to be used TLS Validate.It will be required only if `validate_certs_disable` set to `false`.Can be set via the `BIGIP_TRUSTED_CERT_PATH` environment variable.

~> **Note** For BIG-IQ resources these provider credentials `address`,`username`,`password` can be set to BIG-IQ credentials.

~> **Note** The F5 BIG-IP provider gathers non-identifiable usage data for the purposes of improving the product as outlined in the end user license agreement for BIG-IP. To opt out of data collection, use the following : `export TEEM_DISABLE=true`
~> **Note** The F5 BIG-IP provider gathers non-identifiable usage data for the purposes of improving the product as outlined in the end user license agreement for BIG-IP. To opt out of data collection, use the following : `export TEEM_DISABLE=true`
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/Azure/azure-storage-blob-go v0.13.0
github.com/Azure/go-autorest/autorest v0.11.18
github.com/Azure/go-autorest/autorest/adal v0.9.13
github.com/f5devcentral/go-bigip v0.0.0-20231120063103-95f22f4d262c
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20231120063103-95f22f4d262c
github.com/f5devcentral/go-bigip v0.0.0-20240102182502-074c3e5c7aee
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240102182502-074c3e5c7aee
github.com/google/uuid v1.3.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/stretchr/testify v1.8.4
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/f5devcentral/go-bigip v0.0.0-20231120063103-95f22f4d262c h1:D0BniMWVM/IOkhNZk17d6ukX2CVnbAhr2MavEDrDQj4=
github.com/f5devcentral/go-bigip v0.0.0-20231120063103-95f22f4d262c/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20231120063103-95f22f4d262c h1:FEs8wSVxdTTZHPwR/GuESA5GXZJi/NulZuOjbiOHD1M=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20231120063103-95f22f4d262c/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U=
github.com/f5devcentral/go-bigip v0.0.0-20240102182502-074c3e5c7aee h1:RVNlRNmKTdRVEacKkgXM+LVM0HZEDY07wneeUXXZTeo=
github.com/f5devcentral/go-bigip v0.0.0-20240102182502-074c3e5c7aee/go.mod h1:0Lkr0fBU6O1yBxF2mt9JFwXpaFbIb/wAY7oM3dMJDdA=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240102182502-074c3e5c7aee h1:fmGl57vb62P4gkOASOURc7IoAxfoaRmPpLXed4uBDoo=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240102182502-074c3e5c7aee/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
Expand Down
53 changes: 51 additions & 2 deletions vendor/github.com/f5devcentral/go-bigip/bigip.go

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

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ github.com/apparentlymart/go-textseg/v13/textseg
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
# github.com/f5devcentral/go-bigip v0.0.0-20231120063103-95f22f4d262c
# github.com/f5devcentral/go-bigip v0.0.0-20240102182502-074c3e5c7aee
## explicit; go 1.20
github.com/f5devcentral/go-bigip
# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20231120063103-95f22f4d262c
# github.com/f5devcentral/go-bigip/f5teem v0.0.0-20240102182502-074c3e5c7aee
## explicit; go 1.13
github.com/f5devcentral/go-bigip/f5teem
# github.com/fatih/color v1.13.0
Expand Down

0 comments on commit 57a0a37

Please sign in to comment.