Home > Back-end >  How to get a data from terraform
How to get a data from terraform

Time:02-24

I need a help in terraform.

I have created a ec2 instance using terraform ,after creating the instance I am login to the aws console and added the storage in the instance what I have created the instance.

Now I made some changes in to the terraform code, after that I ran the terraform plan it is showing, the deleting the storage.

How can I run the terraform apply without deleting the storage.

CodePudding user response:

Its a vary bad practice to manually change resource managed by TF as it results in a drift. Please check TF docs how to deal with that:

CodePudding user response:

As the other answer states, it is bad practice to manually change a Terraform managed resource for the reason you are experiencing.

One possibility that you could look at is bringing the storage that you added under the management of Terraform, this is done by terraform import command.

An example, assuming you have added an EBS volume, would be to declare a Terraform resource for the EBS volume and it's attachement to your instance:

resource "aws_ebs_volume" "example" {
  size = 20
  # other props to match real instance
}

resource "aws_volume_attachment" "ebs_att" {
  device_name = "/dev/sdf"
  volume_id   = aws_ebs_volume.example.id
  instance_id = aws_instance.example.id
}

and then import these using the import commands, the details required for each resource varies but can be found in the documentation for each resource.

$ terraform import aws_ebs_volume.example vol-0123456789abc
$ terraform import aws_volume_attachment.example /dev/sdf:vol-0123456789abc:i-876543321
  • Related