Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Add import functionality (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Borja Clemente <[email protected]>
  • Loading branch information
clebs authored Jan 17, 2020
1 parent 57b0c05 commit 73bba4c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions shoot/resource_shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func ResourceShoot() *schema.Resource {
Exists: resourceServerExists,
Update: resourceServerUpdate,
Delete: resourceServerDelete,
Importer: &schema.ResourceImporter{
State: resourceServerImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(defaultCreateTimeout),
Update: schema.DefaultTimeout(defaultUpdateTimeout),
Expand Down Expand Up @@ -167,6 +170,33 @@ func resourceServerDelete(d *schema.ResourceData, m interface{}) error {
return nil
}

func resourceServerImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
client := m.(*client.Client)
namespace, name, err := flatten.IdParts(d.Id())
if err != nil {
return nil, err
}
mutex_key := fmt.Sprintf(`namespace-%s`, namespace)
shootMutex.Lock(mutex_key)
defer shootMutex.Unlock(mutex_key)
shootsClient := client.GardenerClientSet.Shoots(namespace)

// Wait for cluster if it is still not ready
err = resource.Retry(d.Timeout(schema.TimeoutCreate), waitForShootFunc(shootsClient, name))
if err != nil {
d.SetId("")
return nil, err
}
// Set ID
shoot, err := shootsClient.Get(name, meta_v1.GetOptions{})
if err != nil {
return nil, err
}
d.SetId(flatten.BuildID(shoot.ObjectMeta))

return []*schema.ResourceData{d}, nil
}

func resourceServerExists(d *schema.ResourceData, m interface{}) (bool, error) {
client := m.(*client.Client)
namespace, name, err := flatten.IdParts(d.Id())
Expand Down

0 comments on commit 73bba4c

Please sign in to comment.