Merge pull request #2489 from joshgarnett/aws_instance_monitoring

provider/aws: adding support for detailed monitoring of instances
This commit is contained in:
Mitchell Hashimoto 2015-06-25 09:05:15 -07:00
commit 02624118b3
3 changed files with 19 additions and 0 deletions

View File

@ -148,6 +148,11 @@ func resourceAwsInstance() *schema.Resource {
Optional: true,
},
"monitoring": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"iam_instance_profile": &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
@ -324,6 +329,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
BlockDeviceMappings: instanceOpts.BlockDeviceMappings,
DisableAPITermination: instanceOpts.DisableAPITermination,
EBSOptimized: instanceOpts.EBSOptimized,
Monitoring: instanceOpts.Monitoring,
IAMInstanceProfile: instanceOpts.IAMInstanceProfile,
ImageID: instanceOpts.ImageID,
InstanceType: instanceOpts.InstanceType,
@ -463,6 +469,12 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", instance.SubnetID)
}
d.Set("ebs_optimized", instance.EBSOptimized)
if instance.Monitoring != nil && instance.Monitoring.State != nil {
monitoring_state := *instance.Monitoring.State
d.Set("monitoring", monitoring_state == "enabled" || monitoring_state == "pending")
}
d.Set("tags", tagsToMap(instance.Tags))
// Determine whether we're referring to security groups with
@ -847,6 +859,7 @@ type awsInstanceOpts struct {
BlockDeviceMappings []*ec2.BlockDeviceMapping
DisableAPITermination *bool
EBSOptimized *bool
Monitoring *ec2.RunInstancesMonitoringEnabled
IAMInstanceProfile *ec2.IAMInstanceProfileSpecification
ImageID *string
InstanceType *string
@ -872,6 +885,10 @@ func buildAwsInstanceOpts(
InstanceType: aws.String(d.Get("instance_type").(string)),
}
opts.Monitoring = &ec2.RunInstancesMonitoringEnabled{
Enabled: aws.Boolean(d.Get("monitoring").(bool)),
}
opts.IAMInstanceProfile = &ec2.IAMInstanceProfileSpecification{
Name: aws.String(d.Get("iam_instance_profile").(string)),
}

View File

@ -83,6 +83,7 @@ func resourceAwsSpotInstanceRequestCreate(d *schema.ResourceData, meta interface
LaunchSpecification: &ec2.RequestSpotLaunchSpecification{
BlockDeviceMappings: instanceOpts.BlockDeviceMappings,
EBSOptimized: instanceOpts.EBSOptimized,
Monitoring: instanceOpts.Monitoring,
IAMInstanceProfile: instanceOpts.IAMInstanceProfile,
ImageID: instanceOpts.ImageID,
InstanceType: instanceOpts.InstanceType,

View File

@ -34,6 +34,7 @@ The following arguments are supported:
* `placement_group` - (Optional) The Placement Group to start the instance in.
* `ebs_optimized` - (Optional) If true, the launched EC2 instance will be
EBS-optimized.
* `monitoring` - (Optional) If true, the launched EC2 instance will have detailed monitoring enabled.
* `disable_api_termination` - (Optional) If true, enables [EC2 Instance
Termination Protection](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination)
* `instance_type` - (Required) The type of instance to start