rancher: set environment_id on import (#11594)

This commit is contained in:
Raphaël Pinson 2017-02-03 13:34:26 +01:00 committed by Paul Stack
parent d421829aaa
commit acd7320e1f
4 changed files with 44 additions and 4 deletions

View File

@ -16,7 +16,7 @@ func resourceRancherRegistrationToken() *schema.Resource {
Read: resourceRancherRegistrationTokenRead, Read: resourceRancherRegistrationTokenRead,
Delete: resourceRancherRegistrationTokenDelete, Delete: resourceRancherRegistrationTokenDelete,
Importer: &schema.ResourceImporter{ Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough, State: resourceRancherRegistrationTokenImport,
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -204,6 +204,16 @@ func resourceRancherRegistrationTokenDelete(d *schema.ResourceData, meta interfa
return nil return nil
} }
func resourceRancherRegistrationTokenImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*Config)
regT, err := client.RegistrationToken.ById(d.Id())
if err != nil {
return []*schema.ResourceData{}, err
}
d.Set("environment_id", regT.AccountId)
return []*schema.ResourceData{d}, nil
}
// RegistrationTokenStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // RegistrationTokenStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a Rancher RegistrationToken. // a Rancher RegistrationToken.
func RegistrationTokenStateRefreshFunc(client *rancherClient.RancherClient, regTID string) resource.StateRefreshFunc { func RegistrationTokenStateRefreshFunc(client *rancherClient.RancherClient, regTID string) resource.StateRefreshFunc {

View File

@ -17,7 +17,7 @@ func resourceRancherRegistry() *schema.Resource {
Update: resourceRancherRegistryUpdate, Update: resourceRancherRegistryUpdate,
Delete: resourceRancherRegistryDelete, Delete: resourceRancherRegistryDelete,
Importer: &schema.ResourceImporter{ Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough, State: resourceRancherRegistryImport,
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -210,6 +210,16 @@ func resourceRancherRegistryDelete(d *schema.ResourceData, meta interface{}) err
return nil return nil
} }
func resourceRancherRegistryImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*Config)
reg, err := client.Registry.ById(d.Id())
if err != nil {
return []*schema.ResourceData{}, err
}
d.Set("environment_id", reg.AccountId)
return []*schema.ResourceData{d}, nil
}
// RegistryStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // RegistryStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a Rancher Environment. // a Rancher Environment.
func RegistryStateRefreshFunc(client *rancherClient.RancherClient, registryID string) resource.StateRefreshFunc { func RegistryStateRefreshFunc(client *rancherClient.RancherClient, registryID string) resource.StateRefreshFunc {

View File

@ -17,7 +17,7 @@ func resourceRancherRegistryCredential() *schema.Resource {
Update: resourceRancherRegistryCredentialUpdate, Update: resourceRancherRegistryCredentialUpdate,
Delete: resourceRancherRegistryCredentialDelete, Delete: resourceRancherRegistryCredentialDelete,
Importer: &schema.ResourceImporter{ Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough, State: resourceRancherRegistryCredentialImport,
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -232,6 +232,16 @@ func resourceRancherRegistryCredentialDelete(d *schema.ResourceData, meta interf
return nil return nil
} }
func resourceRancherRegistryCredentialImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*Config)
regC, err := client.RegistryCredential.ById(d.Id())
if err != nil {
return []*schema.ResourceData{}, err
}
d.Set("environment_id", regC.AccountId)
return []*schema.ResourceData{d}, nil
}
// RegistryCredentialStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // RegistryCredentialStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a Rancher Environment. // a Rancher Environment.
func RegistryCredentialStateRefreshFunc(client *rancherClient.RancherClient, registryCredID string) resource.StateRefreshFunc { func RegistryCredentialStateRefreshFunc(client *rancherClient.RancherClient, registryCredID string) resource.StateRefreshFunc {

View File

@ -19,7 +19,7 @@ func resourceRancherStack() *schema.Resource {
Update: resourceRancherStackUpdate, Update: resourceRancherStackUpdate,
Delete: resourceRancherStackDelete, Delete: resourceRancherStackDelete,
Importer: &schema.ResourceImporter{ Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough, State: resourceRancherStackImport,
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -333,6 +333,16 @@ func resourceRancherStackDelete(d *schema.ResourceData, meta interface{}) error
return nil return nil
} }
func resourceRancherStackImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*Config)
stack, err := client.Environment.ById(d.Id())
if err != nil {
return []*schema.ResourceData{}, err
}
d.Set("environment_id", stack.AccountId)
return []*schema.ResourceData{d}, nil
}
// StackStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch // StackStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a Rancher Stack. // a Rancher Stack.
func StackStateRefreshFunc(client *rancherClient.RancherClient, stackID string) resource.StateRefreshFunc { func StackStateRefreshFunc(client *rancherClient.RancherClient, stackID string) resource.StateRefreshFunc {