github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/volumeAttachment.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package ec2 5 6 import ( 7 "context" 8 "reflect" 9 10 "errors" 11 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 12 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 13 ) 14 15 // Provides an AWS EBS Volume Attachment as a top level resource, to attach and 16 // detach volumes from AWS Instances. 17 // 18 // > **NOTE on EBS block devices:** If you use `ebsBlockDevice` on an `ec2.Instance`, this provider will assume management over the full set of non-root EBS block devices for the instance, and treats additional block devices as drift. For this reason, `ebsBlockDevice` cannot be mixed with external `ebs.Volume` + `ec2.VolumeAttachment` resources for a given instance. 19 // 20 // ## Example Usage 21 // 22 // <!--Start PulumiCodeChooser --> 23 // ```go 24 // package main 25 // 26 // import ( 27 // 28 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ebs" 29 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2" 30 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 31 // 32 // ) 33 // 34 // func main() { 35 // pulumi.Run(func(ctx *pulumi.Context) error { 36 // web, err := ec2.NewInstance(ctx, "web", &ec2.InstanceArgs{ 37 // Ami: pulumi.String("ami-21f78e11"), 38 // AvailabilityZone: pulumi.String("us-west-2a"), 39 // InstanceType: pulumi.String(ec2.InstanceType_T2_Micro), 40 // Tags: pulumi.StringMap{ 41 // "Name": pulumi.String("HelloWorld"), 42 // }, 43 // }) 44 // if err != nil { 45 // return err 46 // } 47 // example, err := ebs.NewVolume(ctx, "example", &ebs.VolumeArgs{ 48 // AvailabilityZone: pulumi.String("us-west-2a"), 49 // Size: pulumi.Int(1), 50 // }) 51 // if err != nil { 52 // return err 53 // } 54 // _, err = ec2.NewVolumeAttachment(ctx, "ebs_att", &ec2.VolumeAttachmentArgs{ 55 // DeviceName: pulumi.String("/dev/sdh"), 56 // VolumeId: example.ID(), 57 // InstanceId: web.ID(), 58 // }) 59 // if err != nil { 60 // return err 61 // } 62 // return nil 63 // }) 64 // } 65 // 66 // ``` 67 // <!--End PulumiCodeChooser --> 68 // 69 // ## Import 70 // 71 // Using `pulumi import`, import EBS Volume Attachments using `DEVICE_NAME:VOLUME_ID:INSTANCE_ID`. For example: 72 // 73 // ```sh 74 // $ pulumi import aws:ec2/volumeAttachment:VolumeAttachment example /dev/sdh:vol-049df61146c4d7901:i-12345678 75 // ``` 76 type VolumeAttachment struct { 77 pulumi.CustomResourceState 78 79 // The device name to expose to the instance (for 80 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 81 DeviceName pulumi.StringOutput `pulumi:"deviceName"` 82 // Set to `true` if you want to force the 83 // volume to detach. Useful if previous attempts failed, but use this option only 84 // as a last resort, as this can result in **data loss**. See 85 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 86 ForceDetach pulumi.BoolPtrOutput `pulumi:"forceDetach"` 87 // ID of the Instance to attach to 88 InstanceId pulumi.StringOutput `pulumi:"instanceId"` 89 // Set this to true if you do not wish 90 // to detach the volume from the instance to which it is attached at destroy 91 // time, and instead just remove the attachment from this provider state. This is 92 // useful when destroying an instance which has volumes created by some other 93 // means attached. 94 SkipDestroy pulumi.BoolPtrOutput `pulumi:"skipDestroy"` 95 // Set this to true to ensure that the target instance is stopped 96 // before trying to detach the volume. Stops the instance, if it is not already stopped. 97 StopInstanceBeforeDetaching pulumi.BoolPtrOutput `pulumi:"stopInstanceBeforeDetaching"` 98 // ID of the Volume to be attached 99 VolumeId pulumi.StringOutput `pulumi:"volumeId"` 100 } 101 102 // NewVolumeAttachment registers a new resource with the given unique name, arguments, and options. 103 func NewVolumeAttachment(ctx *pulumi.Context, 104 name string, args *VolumeAttachmentArgs, opts ...pulumi.ResourceOption) (*VolumeAttachment, error) { 105 if args == nil { 106 return nil, errors.New("missing one or more required arguments") 107 } 108 109 if args.DeviceName == nil { 110 return nil, errors.New("invalid value for required argument 'DeviceName'") 111 } 112 if args.InstanceId == nil { 113 return nil, errors.New("invalid value for required argument 'InstanceId'") 114 } 115 if args.VolumeId == nil { 116 return nil, errors.New("invalid value for required argument 'VolumeId'") 117 } 118 opts = internal.PkgResourceDefaultOpts(opts) 119 var resource VolumeAttachment 120 err := ctx.RegisterResource("aws:ec2/volumeAttachment:VolumeAttachment", name, args, &resource, opts...) 121 if err != nil { 122 return nil, err 123 } 124 return &resource, nil 125 } 126 127 // GetVolumeAttachment gets an existing VolumeAttachment resource's state with the given name, ID, and optional 128 // state properties that are used to uniquely qualify the lookup (nil if not required). 129 func GetVolumeAttachment(ctx *pulumi.Context, 130 name string, id pulumi.IDInput, state *VolumeAttachmentState, opts ...pulumi.ResourceOption) (*VolumeAttachment, error) { 131 var resource VolumeAttachment 132 err := ctx.ReadResource("aws:ec2/volumeAttachment:VolumeAttachment", name, id, state, &resource, opts...) 133 if err != nil { 134 return nil, err 135 } 136 return &resource, nil 137 } 138 139 // Input properties used for looking up and filtering VolumeAttachment resources. 140 type volumeAttachmentState struct { 141 // The device name to expose to the instance (for 142 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 143 DeviceName *string `pulumi:"deviceName"` 144 // Set to `true` if you want to force the 145 // volume to detach. Useful if previous attempts failed, but use this option only 146 // as a last resort, as this can result in **data loss**. See 147 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 148 ForceDetach *bool `pulumi:"forceDetach"` 149 // ID of the Instance to attach to 150 InstanceId *string `pulumi:"instanceId"` 151 // Set this to true if you do not wish 152 // to detach the volume from the instance to which it is attached at destroy 153 // time, and instead just remove the attachment from this provider state. This is 154 // useful when destroying an instance which has volumes created by some other 155 // means attached. 156 SkipDestroy *bool `pulumi:"skipDestroy"` 157 // Set this to true to ensure that the target instance is stopped 158 // before trying to detach the volume. Stops the instance, if it is not already stopped. 159 StopInstanceBeforeDetaching *bool `pulumi:"stopInstanceBeforeDetaching"` 160 // ID of the Volume to be attached 161 VolumeId *string `pulumi:"volumeId"` 162 } 163 164 type VolumeAttachmentState struct { 165 // The device name to expose to the instance (for 166 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 167 DeviceName pulumi.StringPtrInput 168 // Set to `true` if you want to force the 169 // volume to detach. Useful if previous attempts failed, but use this option only 170 // as a last resort, as this can result in **data loss**. See 171 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 172 ForceDetach pulumi.BoolPtrInput 173 // ID of the Instance to attach to 174 InstanceId pulumi.StringPtrInput 175 // Set this to true if you do not wish 176 // to detach the volume from the instance to which it is attached at destroy 177 // time, and instead just remove the attachment from this provider state. This is 178 // useful when destroying an instance which has volumes created by some other 179 // means attached. 180 SkipDestroy pulumi.BoolPtrInput 181 // Set this to true to ensure that the target instance is stopped 182 // before trying to detach the volume. Stops the instance, if it is not already stopped. 183 StopInstanceBeforeDetaching pulumi.BoolPtrInput 184 // ID of the Volume to be attached 185 VolumeId pulumi.StringPtrInput 186 } 187 188 func (VolumeAttachmentState) ElementType() reflect.Type { 189 return reflect.TypeOf((*volumeAttachmentState)(nil)).Elem() 190 } 191 192 type volumeAttachmentArgs struct { 193 // The device name to expose to the instance (for 194 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 195 DeviceName string `pulumi:"deviceName"` 196 // Set to `true` if you want to force the 197 // volume to detach. Useful if previous attempts failed, but use this option only 198 // as a last resort, as this can result in **data loss**. See 199 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 200 ForceDetach *bool `pulumi:"forceDetach"` 201 // ID of the Instance to attach to 202 InstanceId string `pulumi:"instanceId"` 203 // Set this to true if you do not wish 204 // to detach the volume from the instance to which it is attached at destroy 205 // time, and instead just remove the attachment from this provider state. This is 206 // useful when destroying an instance which has volumes created by some other 207 // means attached. 208 SkipDestroy *bool `pulumi:"skipDestroy"` 209 // Set this to true to ensure that the target instance is stopped 210 // before trying to detach the volume. Stops the instance, if it is not already stopped. 211 StopInstanceBeforeDetaching *bool `pulumi:"stopInstanceBeforeDetaching"` 212 // ID of the Volume to be attached 213 VolumeId string `pulumi:"volumeId"` 214 } 215 216 // The set of arguments for constructing a VolumeAttachment resource. 217 type VolumeAttachmentArgs struct { 218 // The device name to expose to the instance (for 219 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 220 DeviceName pulumi.StringInput 221 // Set to `true` if you want to force the 222 // volume to detach. Useful if previous attempts failed, but use this option only 223 // as a last resort, as this can result in **data loss**. See 224 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 225 ForceDetach pulumi.BoolPtrInput 226 // ID of the Instance to attach to 227 InstanceId pulumi.StringInput 228 // Set this to true if you do not wish 229 // to detach the volume from the instance to which it is attached at destroy 230 // time, and instead just remove the attachment from this provider state. This is 231 // useful when destroying an instance which has volumes created by some other 232 // means attached. 233 SkipDestroy pulumi.BoolPtrInput 234 // Set this to true to ensure that the target instance is stopped 235 // before trying to detach the volume. Stops the instance, if it is not already stopped. 236 StopInstanceBeforeDetaching pulumi.BoolPtrInput 237 // ID of the Volume to be attached 238 VolumeId pulumi.StringInput 239 } 240 241 func (VolumeAttachmentArgs) ElementType() reflect.Type { 242 return reflect.TypeOf((*volumeAttachmentArgs)(nil)).Elem() 243 } 244 245 type VolumeAttachmentInput interface { 246 pulumi.Input 247 248 ToVolumeAttachmentOutput() VolumeAttachmentOutput 249 ToVolumeAttachmentOutputWithContext(ctx context.Context) VolumeAttachmentOutput 250 } 251 252 func (*VolumeAttachment) ElementType() reflect.Type { 253 return reflect.TypeOf((**VolumeAttachment)(nil)).Elem() 254 } 255 256 func (i *VolumeAttachment) ToVolumeAttachmentOutput() VolumeAttachmentOutput { 257 return i.ToVolumeAttachmentOutputWithContext(context.Background()) 258 } 259 260 func (i *VolumeAttachment) ToVolumeAttachmentOutputWithContext(ctx context.Context) VolumeAttachmentOutput { 261 return pulumi.ToOutputWithContext(ctx, i).(VolumeAttachmentOutput) 262 } 263 264 // VolumeAttachmentArrayInput is an input type that accepts VolumeAttachmentArray and VolumeAttachmentArrayOutput values. 265 // You can construct a concrete instance of `VolumeAttachmentArrayInput` via: 266 // 267 // VolumeAttachmentArray{ VolumeAttachmentArgs{...} } 268 type VolumeAttachmentArrayInput interface { 269 pulumi.Input 270 271 ToVolumeAttachmentArrayOutput() VolumeAttachmentArrayOutput 272 ToVolumeAttachmentArrayOutputWithContext(context.Context) VolumeAttachmentArrayOutput 273 } 274 275 type VolumeAttachmentArray []VolumeAttachmentInput 276 277 func (VolumeAttachmentArray) ElementType() reflect.Type { 278 return reflect.TypeOf((*[]*VolumeAttachment)(nil)).Elem() 279 } 280 281 func (i VolumeAttachmentArray) ToVolumeAttachmentArrayOutput() VolumeAttachmentArrayOutput { 282 return i.ToVolumeAttachmentArrayOutputWithContext(context.Background()) 283 } 284 285 func (i VolumeAttachmentArray) ToVolumeAttachmentArrayOutputWithContext(ctx context.Context) VolumeAttachmentArrayOutput { 286 return pulumi.ToOutputWithContext(ctx, i).(VolumeAttachmentArrayOutput) 287 } 288 289 // VolumeAttachmentMapInput is an input type that accepts VolumeAttachmentMap and VolumeAttachmentMapOutput values. 290 // You can construct a concrete instance of `VolumeAttachmentMapInput` via: 291 // 292 // VolumeAttachmentMap{ "key": VolumeAttachmentArgs{...} } 293 type VolumeAttachmentMapInput interface { 294 pulumi.Input 295 296 ToVolumeAttachmentMapOutput() VolumeAttachmentMapOutput 297 ToVolumeAttachmentMapOutputWithContext(context.Context) VolumeAttachmentMapOutput 298 } 299 300 type VolumeAttachmentMap map[string]VolumeAttachmentInput 301 302 func (VolumeAttachmentMap) ElementType() reflect.Type { 303 return reflect.TypeOf((*map[string]*VolumeAttachment)(nil)).Elem() 304 } 305 306 func (i VolumeAttachmentMap) ToVolumeAttachmentMapOutput() VolumeAttachmentMapOutput { 307 return i.ToVolumeAttachmentMapOutputWithContext(context.Background()) 308 } 309 310 func (i VolumeAttachmentMap) ToVolumeAttachmentMapOutputWithContext(ctx context.Context) VolumeAttachmentMapOutput { 311 return pulumi.ToOutputWithContext(ctx, i).(VolumeAttachmentMapOutput) 312 } 313 314 type VolumeAttachmentOutput struct{ *pulumi.OutputState } 315 316 func (VolumeAttachmentOutput) ElementType() reflect.Type { 317 return reflect.TypeOf((**VolumeAttachment)(nil)).Elem() 318 } 319 320 func (o VolumeAttachmentOutput) ToVolumeAttachmentOutput() VolumeAttachmentOutput { 321 return o 322 } 323 324 func (o VolumeAttachmentOutput) ToVolumeAttachmentOutputWithContext(ctx context.Context) VolumeAttachmentOutput { 325 return o 326 } 327 328 // The device name to expose to the instance (for 329 // example, `/dev/sdh` or `xvdh`). See [Device Naming on Linux Instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html#available-ec2-device-names) and [Device Naming on Windows Instances](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/device_naming.html#available-ec2-device-names) for more information. 330 func (o VolumeAttachmentOutput) DeviceName() pulumi.StringOutput { 331 return o.ApplyT(func(v *VolumeAttachment) pulumi.StringOutput { return v.DeviceName }).(pulumi.StringOutput) 332 } 333 334 // Set to `true` if you want to force the 335 // volume to detach. Useful if previous attempts failed, but use this option only 336 // as a last resort, as this can result in **data loss**. See 337 // [Detaching an Amazon EBS Volume from an Instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html) for more information. 338 func (o VolumeAttachmentOutput) ForceDetach() pulumi.BoolPtrOutput { 339 return o.ApplyT(func(v *VolumeAttachment) pulumi.BoolPtrOutput { return v.ForceDetach }).(pulumi.BoolPtrOutput) 340 } 341 342 // ID of the Instance to attach to 343 func (o VolumeAttachmentOutput) InstanceId() pulumi.StringOutput { 344 return o.ApplyT(func(v *VolumeAttachment) pulumi.StringOutput { return v.InstanceId }).(pulumi.StringOutput) 345 } 346 347 // Set this to true if you do not wish 348 // to detach the volume from the instance to which it is attached at destroy 349 // time, and instead just remove the attachment from this provider state. This is 350 // useful when destroying an instance which has volumes created by some other 351 // means attached. 352 func (o VolumeAttachmentOutput) SkipDestroy() pulumi.BoolPtrOutput { 353 return o.ApplyT(func(v *VolumeAttachment) pulumi.BoolPtrOutput { return v.SkipDestroy }).(pulumi.BoolPtrOutput) 354 } 355 356 // Set this to true to ensure that the target instance is stopped 357 // before trying to detach the volume. Stops the instance, if it is not already stopped. 358 func (o VolumeAttachmentOutput) StopInstanceBeforeDetaching() pulumi.BoolPtrOutput { 359 return o.ApplyT(func(v *VolumeAttachment) pulumi.BoolPtrOutput { return v.StopInstanceBeforeDetaching }).(pulumi.BoolPtrOutput) 360 } 361 362 // ID of the Volume to be attached 363 func (o VolumeAttachmentOutput) VolumeId() pulumi.StringOutput { 364 return o.ApplyT(func(v *VolumeAttachment) pulumi.StringOutput { return v.VolumeId }).(pulumi.StringOutput) 365 } 366 367 type VolumeAttachmentArrayOutput struct{ *pulumi.OutputState } 368 369 func (VolumeAttachmentArrayOutput) ElementType() reflect.Type { 370 return reflect.TypeOf((*[]*VolumeAttachment)(nil)).Elem() 371 } 372 373 func (o VolumeAttachmentArrayOutput) ToVolumeAttachmentArrayOutput() VolumeAttachmentArrayOutput { 374 return o 375 } 376 377 func (o VolumeAttachmentArrayOutput) ToVolumeAttachmentArrayOutputWithContext(ctx context.Context) VolumeAttachmentArrayOutput { 378 return o 379 } 380 381 func (o VolumeAttachmentArrayOutput) Index(i pulumi.IntInput) VolumeAttachmentOutput { 382 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *VolumeAttachment { 383 return vs[0].([]*VolumeAttachment)[vs[1].(int)] 384 }).(VolumeAttachmentOutput) 385 } 386 387 type VolumeAttachmentMapOutput struct{ *pulumi.OutputState } 388 389 func (VolumeAttachmentMapOutput) ElementType() reflect.Type { 390 return reflect.TypeOf((*map[string]*VolumeAttachment)(nil)).Elem() 391 } 392 393 func (o VolumeAttachmentMapOutput) ToVolumeAttachmentMapOutput() VolumeAttachmentMapOutput { 394 return o 395 } 396 397 func (o VolumeAttachmentMapOutput) ToVolumeAttachmentMapOutputWithContext(ctx context.Context) VolumeAttachmentMapOutput { 398 return o 399 } 400 401 func (o VolumeAttachmentMapOutput) MapIndex(k pulumi.StringInput) VolumeAttachmentOutput { 402 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *VolumeAttachment { 403 return vs[0].(map[string]*VolumeAttachment)[vs[1].(string)] 404 }).(VolumeAttachmentOutput) 405 } 406 407 func init() { 408 pulumi.RegisterInputType(reflect.TypeOf((*VolumeAttachmentInput)(nil)).Elem(), &VolumeAttachment{}) 409 pulumi.RegisterInputType(reflect.TypeOf((*VolumeAttachmentArrayInput)(nil)).Elem(), VolumeAttachmentArray{}) 410 pulumi.RegisterInputType(reflect.TypeOf((*VolumeAttachmentMapInput)(nil)).Elem(), VolumeAttachmentMap{}) 411 pulumi.RegisterOutputType(VolumeAttachmentOutput{}) 412 pulumi.RegisterOutputType(VolumeAttachmentArrayOutput{}) 413 pulumi.RegisterOutputType(VolumeAttachmentMapOutput{}) 414 }