Skip to content

Commit

Permalink
Merge pull request #42 from DrFaust92/conn-remove
Browse files Browse the repository at this point in the history
Connection - fix removing optional args
  • Loading branch information
DrFaust92 authored Nov 24, 2023
2 parents 74256f1 + 78c69cd commit d5d6048
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/airflow_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following arguments are supported:

* `key` - (Required) The variable key.
* `value` - (Required) The variable value.
* `description` - (Optional) The variable description.

## Attributes Reference

Expand Down
12 changes: 12 additions & 0 deletions internal/provider/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,32 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, m int

if v, ok := d.GetOk("host"); ok {
conn.SetHost(v.(string))
} else {
conn.SetHostNil()
}

if v, ok := d.GetOk("description"); ok {
conn.SetDescription(v.(string))
} else {
conn.SetDescriptionNil()
}

if v, ok := d.GetOk("login"); ok {
conn.SetLogin(v.(string))
} else {
conn.SetLoginNil()
}

if v, ok := d.GetOk("schema"); ok {
conn.SetSchema(v.(string))
} else {
conn.SetSchemaNil()
}

if v, ok := d.GetOk("port"); ok {
conn.SetPort(int32(v.(int)))
} else {
conn.SetPortNil()
}

if v, ok := d.GetOk("password"); ok && v.(string) != "" {
Expand All @@ -198,6 +208,8 @@ func resourceConnectionUpdate(ctx context.Context, d *schema.ResourceData, m int

if v, ok := d.GetOk("extra"); ok {
conn.SetExtra(v.(string))
} else {
conn.SetExtraNil()
}

_, _, err := client.ConnectionApi.PatchConnection(pcfg.AuthContext, connId).Connection(conn).Execute()
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/resource_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ func TestAccAirflowConnection_full(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "description", rNameUpdated),
),
},
{
Config: testAccAirflowConnectionConfigBasic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "connection_id", rName),
resource.TestCheckResourceAttr(resourceName, "conn_type", "http"),
resource.TestCheckResourceAttr(resourceName, "extra", ""),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "port", "0"),
resource.TestCheckResourceAttr(resourceName, "schema", ""),
resource.TestCheckResourceAttr(resourceName, "login", ""),
resource.TestCheckResourceAttr(resourceName, "host", ""),
),
},
},
})
}
Expand Down

0 comments on commit d5d6048

Please sign in to comment.