diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index c710736cc..1d9ebc12a 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -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)), } diff --git a/builtin/providers/aws/resource_aws_spot_instance_request.go b/builtin/providers/aws/resource_aws_spot_instance_request.go index 05b149fe2..c44bdc79d 100644 --- a/builtin/providers/aws/resource_aws_spot_instance_request.go +++ b/builtin/providers/aws/resource_aws_spot_instance_request.go @@ -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, diff --git a/website/source/docs/providers/aws/r/instance.html.markdown b/website/source/docs/providers/aws/r/instance.html.markdown index 5181c6bf3..a524413a7 100644 --- a/website/source/docs/providers/aws/r/instance.html.markdown +++ b/website/source/docs/providers/aws/r/instance.html.markdown @@ -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