Merge pull request #667 from svanharmelen/f-fix-schema-aws-internet-gateway
provider/aws: fixing the aws_internet_gateway resource
This commit is contained in:
commit
cbd913259a
|
@ -20,8 +20,7 @@ func resourceAwsInternetGateway() *schema.Resource {
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"vpc_id": &schema.Schema{
|
"vpc_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -66,13 +65,19 @@ func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) er
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// If we're already attached, detach it first
|
if d.HasChange("vpc_id") {
|
||||||
if err := resourceAwsInternetGatewayDetach(d, meta); err != nil {
|
// If we're already attached, detach it first
|
||||||
return err
|
if err := resourceAwsInternetGatewayDetach(d, meta); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach the gateway to the new vpc
|
||||||
|
if err := resourceAwsInternetGatewayAttach(d, meta); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach the gateway to the new vpc
|
return nil
|
||||||
return resourceAwsInternetGatewayAttach(d, meta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
@ -126,6 +131,13 @@ func resourceAwsInternetGatewayDelete(d *schema.ResourceData, meta interface{})
|
||||||
func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
if d.Get("vpc_id").(string) == "" {
|
||||||
|
log.Printf(
|
||||||
|
"[DEBUG] Not attaching Internet Gateway '%s' as no VPC ID is set",
|
||||||
|
d.Id())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Attaching Internet Gateway '%s' to VPC '%s'",
|
"[INFO] Attaching Internet Gateway '%s' to VPC '%s'",
|
||||||
d.Id(),
|
d.Id(),
|
||||||
|
@ -161,13 +173,23 @@ func resourceAwsInternetGatewayAttach(d *schema.ResourceData, meta interface{})
|
||||||
func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{}) error {
|
||||||
ec2conn := meta.(*AWSClient).ec2conn
|
ec2conn := meta.(*AWSClient).ec2conn
|
||||||
|
|
||||||
|
// Get the old VPC ID to detach from
|
||||||
|
vpc_id, _ := d.GetChange("vpc_id")
|
||||||
|
|
||||||
|
if vpc_id.(string) == "" {
|
||||||
|
log.Printf(
|
||||||
|
"[DEBUG] Not detaching Internet Gateway '%s' as no VPC ID is set",
|
||||||
|
d.Id())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[INFO] Detaching Internet Gateway '%s' from VPC '%s'",
|
"[INFO] Detaching Internet Gateway '%s' from VPC '%s'",
|
||||||
d.Id(),
|
d.Id(),
|
||||||
d.Get("vpc_id").(string))
|
vpc_id.(string))
|
||||||
|
|
||||||
wait := true
|
wait := true
|
||||||
_, err := ec2conn.DetachInternetGateway(d.Id(), d.Get("vpc_id").(string))
|
_, err := ec2conn.DetachInternetGateway(d.Id(), vpc_id.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec2err, ok := err.(*ec2.Error)
|
ec2err, ok := err.(*ec2.Error)
|
||||||
if ok {
|
if ok {
|
||||||
|
|
Loading…
Reference in New Issue