Terraform destroying and creating new instance after instance type change

Hi,

I just changed the ec2 instance type from console and then did in my code change as well but my TF plan showing weird as below. Any idea why this destroying and creating replacement.

-/+ resource "aws_instance" "iexams_mgmt_ec2wav" {
        ami                          = "ami-0aba8f8809d92c31f"
      ~ arn                          = "arn:aws:ec2:ap-southeast-1:618910063946:instance/i-0d363e9378e4ba1d6" -> (known after apply)
      ~ associate_public_ip_address  = false -> (known after apply)
      ~ availability_zone            = "ap-southeast-1c" -> (known after apply)
      ~ cpu_core_count               = 2 -> (known after apply)
      ~ cpu_threads_per_core         = 2 -> (known after apply)
      - disable_api_termination      = true -> null
      - ebs_optimized                = true -> null # forces replacement
        get_password_data            = false
      - hibernation                  = false -> null
      + host_id                      = (known after apply)
        iam_instance_profile         = "iamprof-sxm-uatmz-wav"
      ~ id                           = "i-0d363e9378e4ba1d6" -> (known after apply)
      ~ instance_state               = "running" -> (known after apply)
        instance_type                = "t3.xlarge"
      ~ ipv6_address_count           = 0 -> (known after apply)
      ~ ipv6_addresses               = [] -> (known after apply)
        key_name                     = "kp-sxm-uatmz-wav"
      - monitoring                   = false -> null
      + network_interface_id         = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      ~ primary_network_interface_id = "eni-03f097e3abc28f7dd" -> (known after apply)
      ~ private_dns                  = "ip-172-16-159-57.ap-southeast-1.compute.internal" -> (known after apply)
      ~ private_ip                   = "172.16.159.57" -> (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      ~ security_groups              = [] -> (known after apply)
        source_dest_check            = true
        subnet_id                    = "subnet-0b62c74e935579be5"
        tags                         = {
            "Backup"               = "Yes"
            "Name"                 = "vm-sxm-uatmztmt-wavu01-sxm"
            "OS"                   = "Windows 2016"
            "Patch Group"          = "ssmpg-sxm-uatmztmt-wav"
            "agency-code"          = "seab"
            "environment"          = "uat"
            "hostname"             = "wavu01-sxm"
            "miid"                 = ""
            "ops:running-schedule" = "iEXAMS_AutoShutdown130to730_Weekend22to10"
            "project-code"         = "sxm"
            "purpose"              = "iExams management general tier windows AV."

   }
      ~ tenancy                      = "default" -> (known after apply)
        user_data                    = "060b6ad9543dbee7fbbd6fb86a0eb2c0334cca48"
        volume_tags                  = {
            "Backup"       = "Yes"
            "Name"         = "bst-ebs-sxm-uatmztmt-wav"
            "agency-code"  = "seab"
            "environment"  = "uat"
            "project-code" = "sxm"
            "purpose"      = "iExams management general tier windows AV."
            "tier"         = "tmt"
            "zone"         = "mz"
        }
        vpc_security_group_ids       = [
            "sg-0157733e3560b510c",
            "sg-0c83acd7aca1ad82d",
        ]

      - credit_specification {
          - cpu_credits = "standard" -> null
        }

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)

Hi @rachanasinghr4,

The plan says that it is the ebs_optimized argument that doesn’t match between your configuration and your real EC2 instance.

Specifically, it suggests you haven’t set that argument in your configuration, and so the AWS provider thinks you want to unset it. You could avoid this by changing your configuration to set that argument:

ebs_optimized = true
1 Like

Hi apparentlymart

Thank you so much it worked. Thanks a lot🙏