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

Upgrade from 0.11 to 0.12 #120

Closed
mikealbert opened this issue Jul 30, 2019 · 2 comments
Closed

Upgrade from 0.11 to 0.12 #120

mikealbert opened this issue Jul 30, 2019 · 2 comments

Comments

@mikealbert
Copy link

Hi,

Thanks for all your work on this module. It's been super helpful as we've started to make use of Terraform in our environment.

I have a question about the best way to upgrade from 0.11 to 0.12 with this module. I've built a small test case, but when I upgrade to 0.12 terraform plan reports it will destroy/add an existing instance. I've made sure that terraform plan comes back clean before running the upgrade to 0.12.

Here's my 0.11 tf file

module "foo-lab-sg" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "2.16.0"

  name        = "foo-lab"
  description = "Security group for testing Terraform 0.12 upgrade"
  vpc_id      = "vpc-cd2b9fa9"

  ingress_cidr_blocks = ["0.0.0.0/0"]
  ingress_rules       = ["ssh-tcp", "all-icmp", "all-tcp"]
  egress_rules        = ["all-all"]
}

# ec2 instance
module "foo-instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "1.19.0"

  instance_count         = 1
  name                   = "foo"
  ami                    = "ami-011b3ccf1bd6db744"
  key_name               = "AnsibleKeyPair"
  instance_type          = "t2.small"
  subnet_id              = "subnet-2a5fba01"
  vpc_security_group_ids = ["${module.foo-lab-sg.this_security_group_id}"]

  root_block_device = [{
    volume_type = "gp2"
    volume_size = 20
  }]

  volume_tags = {
    Name     = "foo-lab-vol"
    env      = "lab"
  }

  tags = {
    Name     = "foo"
    env      = "lab"
    comment  = "For testing Terraform 0.12 upgrade"
  }
}

Output of terraform plan after creating resources with 0.11

mikealbert@rMBP mike-test (master) $ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

aws_security_group.this_name_prefix: Refreshing state... (ID: sg-080f4efcf9532057a)
aws_security_group_rule.ingress_rules[2]: Refreshing state... (ID: sgrule-65676491)
aws_instance.this_t2: Refreshing state... (ID: i-0286ad208ef7762a0)
aws_security_group_rule.ingress_rules[0]: Refreshing state... (ID: sgrule-3154134916)
aws_security_group_rule.ingress_rules[1]: Refreshing state... (ID: sgrule-1283150866)
aws_security_group_rule.egress_rules: Refreshing state... (ID: sgrule-1339377203)

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

And here's my tf file after running terraform 0.12upgrade and pointing to the new modules.

module "foo-lab-sg" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "3.1.0"

  name        = "foo-lab"
  description = "Security group for testing Terraform 0.12 upgrade"
  vpc_id      = "vpc-cd2b9fa9"

  ingress_cidr_blocks = ["0.0.0.0/0"]
  ingress_rules       = ["ssh-tcp", "all-icmp", "all-tcp"]
  egress_rules        = ["all-all"]
}

# ec2 instance
module "foo-instance" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "2.6.0"

  instance_count         = 1
  name                   = "foo"
  ami                    = "ami-011b3ccf1bd6db744"
  key_name               = "AnsibleKeyPair"
  instance_type          = "t2.small"
  subnet_id              = "subnet-2a5fba01"
  vpc_security_group_ids = [module.foo-lab-sg.this_security_group_id]

  root_block_device = [
    {
      volume_type = "gp2"
      volume_size = 20
    },
  ]

  volume_tags = {
    Name = "foo-lab-vol"
    env  = "lab"
  }

  tags = {
    Name    = "foo"
    env     = "lab"
    comment = "For testing Terraform 0.12 upgrade"
  }
}

And here's the output of terraform plan after upgrading to 0.12

mikealbert@rMBP mike-test (master) $ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

module.foo-lab-sg.aws_security_group.this_name_prefix[0]: Refreshing state... [id=sg-080f4efcf9532057a]
module.foo-instance.aws_instance.this_t2: Refreshing state... [id=i-0286ad208ef7762a0]
module.foo-lab-sg.aws_security_group_rule.egress_rules[0]: Refreshing state... [id=sgrule-1339377203]
module.foo-lab-sg.aws_security_group_rule.ingress_rules[2]: Refreshing state... [id=sgrule-65676491]
module.foo-lab-sg.aws_security_group_rule.ingress_rules[1]: Refreshing state... [id=sgrule-1283150866]
module.foo-lab-sg.aws_security_group_rule.ingress_rules[0]: Refreshing state... [id=sgrule-3154134916]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  # module.foo-instance.aws_instance.this[0] will be created
  + resource "aws_instance" "this" {
      + ami                          = "ami-011b3ccf1bd6db744"
      + arn                          = (known after apply)
      + associate_public_ip_address  = false
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + disable_api_termination      = false
      + ebs_optimized                = false
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.small"
      + ipv6_address_count           = 0
      + ipv6_addresses               = []
      + key_name                     = "AnsibleKeyPair"
      + monitoring                   = false
      + network_interface_id         = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (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-2a5fba01"
      + tags                         = {
          + "Name"    = "foo"
          + "comment" = "For testing Terraform 0.12 upgrade"
          + "env"     = "lab"
        }
      + tenancy                      = "default"
      + volume_tags                  = {
          + "Name" = "foo-lab-vol"
          + "env"  = "lab"
        }
      + vpc_security_group_ids       = [
          + "sg-080f4efcf9532057a",
        ]

      + credit_specification {
          + cpu_credits = "standard"
        }

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (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)
        }

      + root_block_device {
          + delete_on_termination = true
          + iops                  = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = 20
          + volume_type           = "gp2"
        }
    }

  # module.foo-instance.aws_instance.this_t2 will be destroyed
  - resource "aws_instance" "this_t2" {
      - ami                          = "ami-011b3ccf1bd6db744" -> null
      - arn                          = "arn:aws:ec2:us-east-1:056154071827:instance/i-0286ad208ef7762a0" -> null
      - associate_public_ip_address  = false -> null
      - availability_zone            = "us-east-1a" -> null
      - cpu_core_count               = 1 -> null
      - cpu_threads_per_core         = 1 -> null
      - disable_api_termination      = false -> null
      - ebs_optimized                = false -> null
      - get_password_data            = false -> null
      - id                           = "i-0286ad208ef7762a0" -> null
      - instance_state               = "running" -> null
      - instance_type                = "t2.small" -> null
      - ipv6_address_count           = 0 -> null
      - ipv6_addresses               = [] -> null
      - key_name                     = "AnsibleKeyPair" -> null
      - monitoring                   = false -> null
      - primary_network_interface_id = "eni-02af20d42af9b3237" -> null
      - private_dns                  = "ip-10-16-20-175.ec2.internal" -> null
      - private_ip                   = "10.16.20.175" -> null
      - security_groups              = [] -> null
      - source_dest_check            = true -> null
      - subnet_id                    = "subnet-2a5fba01" -> null
      - tags                         = {
          - "Name"    = "foo"
          - "comment" = "For testing Terraform 0.12 upgrade"
          - "env"     = "lab"
        } -> null
      - tenancy                      = "default" -> null
      - volume_tags                  = {
          - "Name" = "foo-lab-vol"
          - "env"  = "lab"
        } -> null
      - vpc_security_group_ids       = [
          - "sg-080f4efcf9532057a",
        ] -> null

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

      - root_block_device {
          - delete_on_termination = true -> null
          - iops                  = 100 -> null
          - volume_id             = "vol-0719a466e2d430601" -> null
          - volume_size           = 20 -> null
          - volume_type           = "gp2" -> null
        }

      - timeouts {}
    }

Plan: 1 to add, 0 to change, 1 to destroy.

I swapped out the module for a standard aws_instance resource and I don't encounter any issues when upgrading from 0.11 to 0.12. Is there a step or something that I'm missing when upgrading resources that are created via the module? Thanks for the help.

@mikealbert
Copy link
Author

Found the solution here --> #111 (comment)

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant