move a hardcoded instance (not working)
This commit is contained in:
parent
cb7ac73acb
commit
d9aa192cd1
46
mtdaws/mtd.go
Normal file
46
mtdaws/mtd.go
Normal file
@ -0,0 +1,46 @@
|
||||
package mtdaws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||
"github.com/thefeli73/polemos/state"
|
||||
)
|
||||
|
||||
// AWSMoveInstance moves a specified instance to a new availability region
|
||||
func AWSMoveInstance(config state.Config) (state.Config) {
|
||||
instance := config.MTD.Services[0] // for testing use first instance
|
||||
region, instanceID := DecodeCloudID(instance.CloudID)
|
||||
awsConfig := NewConfig(region, config.AWS.CredentialsPath)
|
||||
svc := ec2.NewFromConfig(awsConfig)
|
||||
|
||||
realInstance, err := getInstanceDetailsFromString(svc, instanceID)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting instance details:", err)
|
||||
return config
|
||||
}
|
||||
|
||||
imageName, err := createImage(svc, instanceID)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating image:", err)
|
||||
return config
|
||||
}
|
||||
fmt.Println("Created image: ", imageName)
|
||||
|
||||
newInstanceID, err := launchInstance(svc, realInstance, imageName)
|
||||
if err != nil {
|
||||
fmt.Println("Error launching instance:", err)
|
||||
return config
|
||||
}
|
||||
fmt.Println("Launched new instance:", newInstanceID)
|
||||
|
||||
err = terminateInstance(svc, instanceID)
|
||||
if err != nil {
|
||||
fmt.Println("Error terminating instance:", err)
|
||||
return config
|
||||
}
|
||||
fmt.Println("Terminated original instance:", instanceID)
|
||||
|
||||
|
||||
return config
|
||||
}
|
Loading…
Reference in New Issue
Block a user