@ -147,6 +147,11 @@ func resourceAwsInstance() *schema.Resource {
Optional : true ,
} ,
"instance_initiated_shutdown_behavior" : & schema . Schema {
Type : schema . TypeString ,
Optional : true ,
} ,
"monitoring" : & schema . Schema {
Type : schema . TypeBool ,
Optional : true ,
@ -331,17 +336,18 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
Monitoring : instanceOpts . Monitoring ,
IamInstanceProfile : instanceOpts . IAMInstanceProfile ,
ImageId : instanceOpts . ImageID ,
InstanceType : instanceOpts . InstanceType ,
KeyName : instanceOpts . KeyName ,
MaxCount : aws . Int64 ( int64 ( 1 ) ) ,
MinCount : aws . Int64 ( int64 ( 1 ) ) ,
NetworkInterfaces : instanceOpts . NetworkInterfaces ,
Placement : instanceOpts . Placement ,
PrivateIpAddress : instanceOpts . PrivateIPAddress ,
SecurityGroupIds : instanceOpts . SecurityGroupIDs ,
SecurityGroups : instanceOpts . SecurityGroups ,
SubnetId : instanceOpts . SubnetID ,
UserData : instanceOpts . UserData64 ,
InstanceInitiatedShutdownBehavior : instanceOpts . InstanceInitiatedShutdownBehavior ,
InstanceType : instanceOpts . InstanceType ,
KeyName : instanceOpts . KeyName ,
MaxCount : aws . Int64 ( int64 ( 1 ) ) ,
MinCount : aws . Int64 ( int64 ( 1 ) ) ,
NetworkInterfaces : instanceOpts . NetworkInterfaces ,
Placement : instanceOpts . Placement ,
PrivateIpAddress : instanceOpts . PrivateIPAddress ,
SecurityGroupIds : instanceOpts . SecurityGroupIDs ,
SecurityGroups : instanceOpts . SecurityGroups ,
SubnetId : instanceOpts . SubnetID ,
UserData : instanceOpts . UserData64 ,
}
// Create the instance
@ -578,6 +584,19 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
}
}
if d . HasChange ( "instance_initiated_shutdown_behavior" ) {
log . Printf ( "[INFO] Modifying instance %s" , d . Id ( ) )
_ , err := conn . ModifyInstanceAttribute ( & ec2 . ModifyInstanceAttributeInput {
InstanceId : aws . String ( d . Id ( ) ) ,
InstanceInitiatedShutdownBehavior : & ec2 . AttributeValue {
Value : aws . String ( d . Get ( "instance_initiated_shutdown_behavior" ) . ( string ) ) ,
} ,
} )
if err != nil {
return err
}
}
if d . HasChange ( "monitoring" ) {
var mErr error
if d . Get ( "monitoring" ) . ( bool ) {
@ -878,22 +897,23 @@ func readBlockDeviceMappingsFromConfig(
}
type awsInstanceOpts struct {
BlockDeviceMappings [ ] * ec2 . BlockDeviceMapping
DisableAPITermination * bool
EBSOptimized * bool
Monitoring * ec2 . RunInstancesMonitoringEnabled
IAMInstanceProfile * ec2 . IamInstanceProfileSpecification
ImageID * string
InstanceType * string
KeyName * string
NetworkInterfaces [ ] * ec2 . InstanceNetworkInterfaceSpecification
Placement * ec2 . Placement
PrivateIPAddress * string
SecurityGroupIDs [ ] * string
SecurityGroups [ ] * string
SpotPlacement * ec2 . SpotPlacement
SubnetID * string
UserData64 * string
BlockDeviceMappings [ ] * ec2 . BlockDeviceMapping
DisableAPITermination * bool
EBSOptimized * bool
Monitoring * ec2 . RunInstancesMonitoringEnabled
IAMInstanceProfile * ec2 . IamInstanceProfileSpecification
ImageID * string
InstanceInitiatedShutdownBehavior * string
InstanceType * string
KeyName * string
NetworkInterfaces [ ] * ec2 . InstanceNetworkInterfaceSpecification
Placement * ec2 . Placement
PrivateIPAddress * string
SecurityGroupIDs [ ] * string
SecurityGroups [ ] * string
SpotPlacement * ec2 . SpotPlacement
SubnetID * string
UserData64 * string
}
func buildAwsInstanceOpts (
@ -907,6 +927,10 @@ func buildAwsInstanceOpts(
InstanceType : aws . String ( d . Get ( "instance_type" ) . ( string ) ) ,
}
if v := d . Get ( "instance_initiated_shutdown_behavior" ) . ( string ) ; v != "" {
opts . InstanceInitiatedShutdownBehavior = aws . String ( v )
}
opts . Monitoring = & ec2 . RunInstancesMonitoringEnabled {
Enabled : aws . Bool ( d . Get ( "monitoring" ) . ( bool ) ) ,
}