crossplane-contrib / provider-upjet-aws

Official AWS Provider for Crossplane by Upbound.
https://marketplace.upbound.io/providers/upbound/provider-aws
Apache License 2.0
137 stars 112 forks source link

[Bug]: Import EC2 Instance with gp2 leads to iops attribute not supported for root_block_device with volume_type gp2 #1306

Closed haarchri closed 1 month ago

haarchri commented 1 month ago

Is there an existing issue for this?

Affected Resource(s)

Resource MRs required to reproduce the bug

No response

Steps to Reproduce

import ec2 instance with gp2 ebs root block device

apiVersion: ec2.aws.upbound.io/v1beta1
kind: Instance
metadata:
  name: importtest1
  annotations:
    crossplane.io/external-name: i-0418d2932007f7c10
spec:
  forProvider:
    region: us-west-1
  providerConfigRef:
    name: xxx

when import ec2 instances with gp3 ebs root block device everything is working as expected:

kubectl get instance.ec2                  
NAME          READY   SYNCED   EXTERNAL-NAME         AGE
importtest1   True    True     i-0418d2932007f7c10   84s

What happened?

the import will lead to:

Status:
  At Provider:
[...]
    Root Block Device:
      Delete On Termination:  true
      Device Name:            /dev/sda1
      Encrypted:              false
      Iops:                   100
      Kms Key Id:
      Throughput:             0
      Volume Id:              vol-0ee29cc94ac635ca6
      Volume Size:            8
      Volume Type:            gp2
[...]
  Conditions:
    Last Transition Time:  2024-05-03T07:10:21Z
    Reason:                Creating
    Status:                False
    Type:                  Ready
    Last Transition Time:  2024-05-03T08:07:33Z
    Reason:                ReconcileSuccess
    Status:                True
    Type:                  Synced
    Last Transition Time:  2024-05-03T07:10:21Z
    Message:               async create failed: failed to create the resource: [{0 collecting instance settings: error creating resource: iops attribute not supported for root_block_device with volume_type gp2  []}]
    Reason:                AsyncCreateFailure
    Status:                False
    Type:                  LastAsyncOperation

Relevant Error Output Snippet

No response

Crossplane Version

1.15.2

Provider Version

1.3.0

Kubernetes Version

No response

Kubernetes Distribution

No response

Additional Info

wonder if the problem is the late init from IOPS field when gp2 is used TF Provider Code: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/ec2_instance.go#L2577-L2588

turkenf commented 1 month ago

@haarchri, could you please provide us the Instance.ec2 MR example you used initially to reproduce the bug?

haarchri commented 1 month ago

this issue will not happen with v1.5.0 again example:

apiVersion: ec2.aws.upbound.io/v1beta1
kind: Instance
metadata:
  annotations:
    uptest.upbound.io/timeout: "3600"
    meta.upbound.io/example-id: ec2/v1beta1/instance
  labels:
    testing.upbound.io/example-name: sample-instance
  name: sample-instance
spec:
  forProvider:
    region: us-west-1
    ami: ami-07b068f843ec78e72
    instanceType: t2.micro
    networkInterface:
    - deviceIndex: 0
      networkInterfaceIdSelector:
        matchLabels:
          testing.upbound.io/example-name: sample-instance
    blockDeviceMappings:
    - deviceName: /dev/xvda
      ebs:
        volumeSize: 100
        volumeType: gp2
    creditSpecification:
    - cpuCredits: unlimited
apiVersion: ec2.aws.upbound.io/v1beta1
kind: Instance
metadata:
  annotations:
    crossplane.io/external-name: i-04f75003c6e2cf24a
  name: import-instance
spec:
  deletionPolicy: Delete
  forProvider:
    region: us-west-1
  managementPolicies:
  - 'Observe'
  providerConfigRef:
    name: default
NAME                                          SYNCED   READY   EXTERNAL-NAME         AGE
instance.ec2.aws.upbound.io/import-instance   True     True    i-04f75003c6e2cf24a   8m54s

NAME                                                  SYNCED   READY   EXTERNAL-NAME           AGE
networkinterface.ec2.aws.upbound.io/sample-instance   True     True    eni-0e5805d46f680354e   26m

NAME                                        SYNCED   READY   EXTERNAL-NAME              AGE
subnet.ec2.aws.upbound.io/sample-instance   True     True    subnet-0a038c9110557b2e6   26m

NAME                                     SYNCED   READY   EXTERNAL-NAME           AGE
vpc.ec2.aws.upbound.io/sample-instance   True     True    vpc-0f610ce590c4df6a5   26m
kubectl describe instance.ec2.aws.upbound.io/import-instance
Name:         import-instance
Namespace:    
Labels:       <none>
Annotations:  crossplane.io/external-name: i-04f75003c6e2cf24a
API Version:  ec2.aws.upbound.io/v1beta1
Kind:         Instance
Metadata:
  Creation Timestamp:  2024-06-04T13:39:30Z
  Finalizers:
    finalizer.managedresource.crossplane.io
  Generation:        2
  Resource Version:  3802
  UID:               3b67d2fb-a74f-4d6b-8cb3-06b1930189dc
Spec:
  Deletion Policy:  Delete
  For Provider:
    Region:  us-west-1
  Init Provider:
  Management Policies:
    Observe
  Provider Config Ref:
    Name:  default
Status:
  At Provider:
    Ami:                          ami-07b068f843ec78e72
    Arn:                          arn:aws:ec2:us-west-1:609897127049:instance/i-04f75003c6e2cf24a
    Associate Public Ip Address:  false
    Availability Zone:            us-west-1b
    Capacity Reservation Specification:
      Capacity Reservation Preference:  open
    Cpu Core Count:                     1
    Cpu Options:
      Amd Sev Snp:         
      Core Count:          1
      Threads Per Core:    1
    Cpu Threads Per Core:  1
    Credit Specification:
      Cpu Credits:            unlimited
    Disable API Stop:         false
    Disable API Termination:  false
    Ebs Optimized:            false
    Enclave Options:
      Enabled:                             false
    Get Password Data:                     false
    Hibernation:                           false
    Host Id:                               
    Iam Instance Profile:                  
    Id:                                    i-04f75003c6e2cf24a
    Instance Initiated Shutdown Behavior:  stop
    Instance Lifecycle:                    
    Instance State:                        running
    Instance Type:                         t2.micro
    ipv6AddressCount:                      0
    Key Name:                              
    Maintenance Options:
      Auto Recovery:  default
    Metadata Options:
      Http Endpoint:                enabled
      httpProtocolIpv6:             disabled
      Http Put Response Hop Limit:  1
      Http Tokens:                  optional
      Instance Metadata Tags:       disabled
    Monitoring:                     false
    Outpost Arn:                    
    Password Data:                  
    Placement Group:                
    Placement Partition Number:     0
    Primary Network Interface Id:   eni-0e5805d46f680354e
    Private Dns:                    ip-172-16-10-100.us-west-1.compute.internal
    Private Dns Name Options:
      Enable Resource Name Dns A Record:     false
      Enable Resource Name Dns Aaaa Record:  false
      Hostname Type:                         ip-name
    Private Ip:                              172.16.10.100
    Public Dns:                              
    Public Ip:                               
    Root Block Device:
      Delete On Termination:   true
      Device Name:             /dev/sda1
      Encrypted:               false
      Iops:                    100
      Kms Key Id:              
      Throughput:              0
      Volume Id:               vol-0fc7d734ea20ee925
      Volume Size:             8
      Volume Type:             gp2
    Source Dest Check:         true
    Spot Instance Request Id:  
    Subnet Id:                 subnet-0a038c9110557b2e6
    Tags:
      Crossplane - Kind:            instance.ec2.aws.upbound.io
      Crossplane - Name:            sample-instance
      Crossplane - Providerconfig:  default
    Tags All:
      Crossplane - Kind:            instance.ec2.aws.upbound.io
      Crossplane - Name:            sample-instance
      Crossplane - Providerconfig:  default
    Tenancy:                        default
    Vpc Security Group Ids:
      sg-08467904e3109316f
  Conditions:
    Last Transition Time:  2024-06-04T13:39:34Z
    Reason:                ReconcileSuccess
    Status:                True
    Type:                  Synced
    Last Transition Time:  2024-06-04T13:39:37Z
    Reason:                Available
    Status:                True
    Type:                  Ready
Events:                    <none>