Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for detailed monitoring of instances #2489

Merged
merged 1 commit into from
Jun 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice nil checks here

monitoring_state := *instance.Monitoring.State
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more idiomatic to use monitoringState, but I can fix that up.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, sorry I've been bouncing between ruby & go lately.

d.Set("monitoring", monitoring_state == "enabled" || monitoring_state == "pending")
}

d.Set("tags", tagsToMap(instance.Tags))

// Determine whether we're referring to security groups with
Expand Down Expand Up @@ -847,6 +859,7 @@ type awsInstanceOpts struct {
BlockDeviceMappings []*ec2.BlockDeviceMapping
DisableAPITermination *bool
EBSOptimized *bool
Monitoring *ec2.RunInstancesMonitoringEnabled
IAMInstanceProfile *ec2.IAMInstanceProfileSpecification
ImageID *string
InstanceType *string
Expand All @@ -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)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions website/source/docs/providers/aws/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down