Skip to content

Commit

Permalink
Merge branch 'main' into dbaas-kafka-topic-support
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinshenker authored Oct 17, 2023
2 parents be11eb7 + 5732de8 commit eaf2227
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 10 deletions.
9 changes: 8 additions & 1 deletion digitalocean/app/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ func waitForAppDeployment(client *godo.Client, id string, timeout time.Duration)
return fmt.Errorf("Error trying to read app deployment state: %s", err)
}

allSuccessful := deployment.Progress.SuccessSteps == deployment.Progress.TotalSteps
allSuccessful := true
for _, step := range deployment.Progress.Steps {
if step.Status != godo.DeploymentProgressStepStatus_Success {
allSuccessful = false
break
}
}

if allSuccessful {
ticker.Stop()
return nil
Expand Down
23 changes: 19 additions & 4 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func TestAccDigitalOceanApp_Job(t *testing.T) {
"digitalocean_app.foobar", "spec.0.job.1.log_destination.0.datadog.0.endpoint", "https://example.com"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.1.log_destination.0.datadog.0.api_key", "test-api-key"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.2.name", "example-failed-job"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.2.kind", "FAILED_DEPLOY"),
),
},
},
Expand Down Expand Up @@ -1189,10 +1193,6 @@ resource "digitalocean_app" "foobar" {
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
branch = "main"
}
routes {
path = "/"
}
}
job {
Expand All @@ -1217,6 +1217,21 @@ resource "digitalocean_app" "foobar" {
}
}
}
job {
name = "example-failed-job"
instance_count = 1
instance_size_slug = "basic-xxs"
kind = "FAILED_DEPLOY"
run_command = "echo 'This is a failed deploy job.'"
image {
registry_type = "DOCKER_HUB"
registry = "frolvlad"
repository = "alpine-bash"
tag = "latest"
}
}
}
}`

Expand Down
38 changes: 33 additions & 5 deletions digitalocean/loadbalancer/resource_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func ResourceDigitalOceanLoadbalancer() *schema.Resource {
}
}

if err := loadbalancerDiffCheck(ctx, diff, v); err != nil {
return err
}

return nil
},
}
Expand Down Expand Up @@ -113,12 +117,35 @@ func resourceDigitalOceanLoadBalancerV1() map[string]*schema.Schema {
return loadBalancerV1Schema
}

func loadbalancerDiffCheck(ctx context.Context, d *schema.ResourceDiff, v interface{}) error {
typ, typSet := d.GetOk("type")
region, regionSet := d.GetOk("region")

if !typSet && !regionSet {
return fmt.Errorf("missing 'region' value")
}

typStr := typ.(string)
switch strings.ToUpper(typStr) {
case "GLOBAL":
if regionSet && region.(string) != "" {
return fmt.Errorf("'region' must be empty or not set when 'type' is '%s'", typStr)
}
case "REGIONAL":
if !regionSet || region.(string) == "" {
return fmt.Errorf("'region' must be set and not be empty when 'type' is '%s'", typStr)
}
}

return nil
}

func resourceDigitalOceanLoadBalancerV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
StateFunc: func(val interface{}) string {
// DO API V2 region slug is always lowercase
Expand Down Expand Up @@ -404,10 +431,11 @@ func resourceDigitalOceanLoadBalancerV0() *schema.Resource {
},
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "the type of the load balancer (GLOBAL or REGIONAL)",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"REGIONAL", "GLOBAL"}, true),
Description: "the type of the load balancer (GLOBAL or REGIONAL)",
},
},
}
Expand Down
96 changes: 96 additions & 0 deletions digitalocean/loadbalancer/resource_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/config"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/loadbalancer"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand Down Expand Up @@ -737,6 +738,101 @@ func TestAccDigitalOceanLoadbalancer_Firewall(t *testing.T) {
})
}

func TestLoadbalancerDiffCheck(t *testing.T) {
cases := []struct {
name string
attrs map[string]interface{}
expectError bool
errorMessage string
}{
{
name: "Missing type and region",
expectError: true,
errorMessage: "missing 'region' value",
},
{
name: "Missing type",
expectError: false,
attrs: map[string]interface{}{
"region": "nyc3",
},
},
{
name: "Empty region",
expectError: true,
errorMessage: "missing 'region' value",
attrs: map[string]interface{}{
"region": "",
},
},
{
name: "Regional type without region",
expectError: true,
errorMessage: "'region' must be set and not be empty when 'type' is 'REGIONAL'",
attrs: map[string]interface{}{
"type": "REGIONAL",
},
},
{
name: "Regional type with empty region",
expectError: true,
errorMessage: "'region' must be set and not be empty when 'type' is 'REGIONAL'",
attrs: map[string]interface{}{
"type": "REGIONAL",
"region": "",
},
},
{
name: "Regional type with region",
expectError: false,
attrs: map[string]interface{}{
"type": "REGIONAL",
"region": "nyc3",
},
},
{
name: "Global type without region",
expectError: false,
attrs: map[string]interface{}{
"type": "GLOBAL",
},
},
{
name: "Global type with empty region",
expectError: false,
attrs: map[string]interface{}{
"type": "GLOBAL",
"region": "",
},
},
{
name: "Global type with region",
expectError: true,
errorMessage: "'region' must be empty or not set when 'type' is 'GLOBAL'",
attrs: map[string]interface{}{
"type": "GLOBAL",
"region": "nyc3",
},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
var s *terraform.InstanceState
conf := terraform.NewResourceConfigRaw(c.attrs)

r := loadbalancer.ResourceDigitalOceanLoadbalancer()
_, err := r.Diff(context.Background(), s, conf, nil)

if c.expectError {
if err.Error() != c.errorMessage {
t.Fatalf("Expected %s, got %s", c.errorMessage, err)
}
}
})
}
}

func testAccCheckDigitalOceanLoadbalancerDestroy(s *terraform.State) error {
client := acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()

Expand Down
30 changes: 30 additions & 0 deletions docs/resources/database_firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ resource "digitalocean_database_cluster" "postgres-example" {
}
```

### Create a new database firewall for a database replica

```hcl
resource "digitalocean_database_cluster" "postgres-example" {
name = "example-postgres-cluster"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
}
resource "digitalocean_database_replica" "replica-example" {
cluster_id = digitalocean_database_cluster.postgres-example.id
name = "replica-example"
size = "db-s-1vcpu-1gb"
region = "nyc1"
}
# Create firewall rule for database replica
resource "digitalocean_database_firewall" "example-fw" {
cluster_id = digitalocean_database_replica.replica-example.uuid
rule {
type = "ip_addr"
value = "192.168.1.1"
}
}
```

## Argument Reference

The following arguments are supported:
Expand Down
24 changes: 24 additions & 0 deletions docs/resources/database_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ resource "digitalocean_database_cluster" "postgres-example" {
}
```

### Create a new user for a PostgreSQL database replica
```hcl
resource "digitalocean_database_cluster" "postgres-example" {
name = "example-postgres-cluster"
engine = "pg"
version = "11"
size = "db-s-1vcpu-1gb"
region = "nyc1"
node_count = 1
}
resource "digitalocean_database_replica" "replica-example" {
cluster_id = digitalocean_database_cluster.postgres-example.id
name = "replica-example"
size = "db-s-1vcpu-1gb"
region = "nyc1"
}
resource "digitalocean_database_user" "user-example" {
cluster_id = digitalocean_database_replica.replica-example.uuid
name = "foobar"
}
```

## Argument Reference

The following arguments are supported:
Expand Down

0 comments on commit eaf2227

Please sign in to comment.