Skip to content

Commit

Permalink
use Id() when reading resource to fix import functionality (#8)
Browse files Browse the repository at this point in the history
* use Id() when reading resource to fix import functionality
* use Id() for updates and deletes too
  • Loading branch information
ajbosco authored Dec 9, 2021
1 parent e442b48 commit 37d3f25
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func resourceUserCreate(d *schema.ResourceData, m interface{}) error {
func resourceUserRead(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
username := d.Get("username").(string)
username := d.Id()

req := client.UserApi.GetUser(pcfg.AuthContext, username)
user, resp, err := req.Execute()
Expand All @@ -65,7 +65,7 @@ func resourceUserRead(d *schema.ResourceData, m interface{}) error {
func resourceUserUpdate(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
username := d.Get("username").(string)
username := d.Id()
email := d.Get("email").(string)
firstName := d.Get("first_name").(string)
lastName := d.Get("last_name").(string)
Expand Down Expand Up @@ -95,7 +95,7 @@ func resourceUserUpdate(d *schema.ResourceData, m interface{}) error {
func resourceUserDelete(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
username := d.Get("username").(string)
username := d.Id()
req := client.UserApi.DeleteUser(pcfg.AuthContext, username)
_, err := req.Execute()
return err
Expand Down
5 changes: 5 additions & 0 deletions resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestAcc_User(t *testing.T) {
resource.TestCheckResourceAttr("airflow_user.test", "username", username),
),
},
{
ResourceName: "airflow_user.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions resource_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func resourceVariableCreate(d *schema.ResourceData, m interface{}) error {
func resourceVariableRead(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
key := d.Get("key").(string)
key := d.Id()

req := client.VariableApi.GetVariable(pcfg.AuthContext, key)
variable, resp, err := req.Execute()
Expand All @@ -52,7 +52,7 @@ func resourceVariableRead(d *schema.ResourceData, m interface{}) error {
func resourceVariableUpdate(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
key := d.Get("key").(string)
key := d.Id()
value := d.Get("value").(string)

v := airflow.Variable{
Expand All @@ -73,7 +73,7 @@ func resourceVariableUpdate(d *schema.ResourceData, m interface{}) error {
func resourceVariableDelete(d *schema.ResourceData, m interface{}) error {
pcfg := m.(ProviderConfig)
client := pcfg.ApiClient
key := d.Get("key").(string)
key := d.Id()
req := client.VariableApi.DeleteVariable(pcfg.AuthContext, key)
_, err := req.Execute()
return err
Expand Down
5 changes: 5 additions & 0 deletions resource_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func TestAcc_Variable(t *testing.T) {
resource.TestCheckResourceAttr("airflow_variable.test", "key", key),
),
},
{
ResourceName: "airflow_variable.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit 37d3f25

Please sign in to comment.