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

Configure Godo Retryable HTTP Client #1016

Merged
merged 20 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions digitalocean/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/digitalocean/godo"
"github.com/hashicorp/go-retryablehttp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -76,25 +74,28 @@ func (c *Config) Client() (*CombinedConfig, error) {

userAgent := fmt.Sprintf("Terraform/%s", c.TerraformVersion)
var client *http.Client
var godoOpts []godo.ClientOpt

client = oauth2.NewClient(context.Background(), tokenSrc)
client.Transport = logging.NewTransport("DigitalOcean", client.Transport)

if c.HTTPRetryMax > 0 {
retryableClient := retryablehttp.NewClient()
retryableClient.RetryMax = c.HTTPRetryMax
retryableClient.RetryWaitMin = time.Duration(c.HTTPRetryWaitMin * float64(time.Second))
retryableClient.RetryWaitMax = time.Duration(c.HTTPRetryWaitMax * float64(time.Second))
retryConfig := godo.RetryConfig{
RetryMax: 3,
RetryWaitMin: godo.PtrTo(c.HTTPRetryWaitMin),
RetryWaitMax: godo.PtrTo(c.HTTPRetryWaitMax),
}

godoOpts = []godo.ClientOpt{godo.WithRetryAndBackoffs(retryConfig)}

client = retryableClient.StandardClient()
client.Transport = &oauth2.Transport{
Base: client.Transport,
Source: oauth2.ReuseTokenSource(nil, tokenSrc),
andrewsomething marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
client = oauth2.NewClient(context.Background(), tokenSrc)
}

client.Transport = logging.NewTransport("DigitalOcean", client.Transport)
godoOpts = append(godoOpts, godo.SetUserAgent(userAgent))

godoOpts := []godo.ClientOpt{godo.SetUserAgent(userAgent)}
if c.RequestsPerSecond > 0.0 {
godoOpts = append(godoOpts, godo.SetStaticRateLimit(c.RequestsPerSecond))
}
Expand Down
10 changes: 5 additions & 5 deletions examples/droplet/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ provider "digitalocean" {

resource "digitalocean_droplet" "mywebserver" {
# Obtain your ssh_key id number via your account. See Document https://developers.digitalocean.com/documentation/v2/#list-all-keys
ssh_keys = [digitalocean_ssh_key.example.fingerprint]
# ssh_keys = [digitalocean_ssh_key.example.fingerprint]
image = var.ubuntu
region = var.do_ams3
size = "s-1vcpu-1gb"
Expand All @@ -34,10 +34,10 @@ resource "digitalocean_droplet" "mywebserver" {
}
}

resource "digitalocean_ssh_key" "example" {
name = "examplekey"
public_key = file(var.ssh_key_path)
}
# resource "digitalocean_ssh_key" "example" {
# name = "examplekey"
# public_key = file(var.ssh_key_path)
# }

resource "digitalocean_domain" "mywebserver" {
name = "www.mywebserver.com"
Expand Down
35 changes: 12 additions & 23 deletions examples/kubernetes/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,17 @@ terraform {
}
}

resource "random_id" "cluster_name" {
byte_length = 5
resource "digitalocean_database_cluster" "postgres-example" {
name = "example-postgres-cluster"
engine = "pg"
version = "13"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
}

locals {
cluster_name = "tf-k8s-${random_id.cluster_name.hex}"
}

module "doks-cluster" {
source = "./doks-cluster"
cluster_name = local.cluster_name
cluster_region = "nyc3"
cluster_version = var.cluster_version

worker_size = var.worker_size
worker_count = var.worker_count
}

module "kubernetes-config" {
source = "./kubernetes-config"
cluster_name = module.doks-cluster.cluster_name
cluster_id = module.doks-cluster.cluster_id

write_kubeconfig = var.write_kubeconfig
}
resource "digitalocean_database_user" "user-example" {
cluster_id = digitalocean_database_cluster.postgres-example.id
name = "${count.index}-app"
count = 260
}
12 changes: 6 additions & 6 deletions examples/kubernetes/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "cluster_name" {
value = module.doks-cluster.cluster_name
}
# output "cluster_name" {
# value = module.doks-cluster.cluster_name
# }

output "kubeconfig_path" {
value = var.write_kubeconfig ? abspath("${path.root}/kubeconfig") : "none"
}
# output "kubeconfig_path" {
# value = var.write_kubeconfig ? abspath("${path.root}/kubeconfig") : "none"
# }
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.42.18
github.com/digitalocean/godo v1.95.0
github.com/digitalocean/godo v1.100.1-0.20230803192756-bc798b06c70f
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.95.0 h1:S48/byPKui7RHZc1wYEPfRvkcEvToADNb5I3guu95xg=
github.com/digitalocean/godo v1.95.0/go.mod h1:NRpFznZFvhHjBoqZAaOD3khVzsJ3EibzKqFL4R60dmA=
github.com/digitalocean/godo v1.100.1-0.20230803192756-bc798b06c70f h1:Dx01wYQznKX/pHFVgPwIruCD+kEmqcPkrYfqhjZTdNw=
github.com/digitalocean/godo v1.100.1-0.20230803192756-bc798b06c70f/go.mod h1:SaUYccN7r+CO1QtsbXGypAsgobDrmSfVMJESEfXgoEg=
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/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -82,6 +84,8 @@ github.com/hashicorp/go-plugin v1.4.8 h1:CHGwpxYDOttQOY7HOWgETU9dyVjOXzniXDqJcYJ
github.com/hashicorp/go-plugin v1.4.8/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down
26 changes: 26 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

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

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/README.md

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

1 change: 1 addition & 0 deletions vendor/github.com/digitalocean/godo/account.go

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

93 changes: 86 additions & 7 deletions vendor/github.com/digitalocean/godo/apps.gen.go

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

7 changes: 6 additions & 1 deletion vendor/github.com/digitalocean/godo/apps.go

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