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

resource/aws_ebs_volume: Not setting the state for ebs_volume correctly #999

Merged
merged 1 commit into from
Jun 29, 2017

Conversation

stack72
Copy link
Contributor

@stack72 stack72 commented Jun 29, 2017

Fixes: #927

When we ran the create, we didn't make a call to the API to Describe the
volume, therefore, we were not actually setting the values to state
based on what the API returned. We also only set the Tags to state if
they were not nil. Therefore, the scenario of someone creating a tag
with Terraform, then removing that tag (and thus no tags are left on the
resource) would mean that Terraform didn't see the state drift:

[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% terraform apply
aws_ebs_volume.hashi-test: Creating...
  availability_zone: "" => "eu-central-1a"
  encrypted:         "" => "<computed>"
  iops:              "" => "<computed>"
  kms_key_id:        "" => "<computed>"
  size:              "" => "5"
  snapshot_id:       "" => "<computed>"
  tags.%:            "" => "1"
  tags.Name:         "" => "hashi-test"
  type:              "" => "<computed>"
aws_ebs_volume.hashi-test: Still creating... (10s elapsed)
aws_ebs_volume.hashi-test: Creation complete (ID: vol-01133d4a2d74aa55b)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:
[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% 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_ebs_volume.hashi-test: Refreshing state... (ID: vol-01133d4a2d74aa55b)
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, Terraform
doesn't need to do anything.

This commit takes care of that but always setting the tags - d.Set handles the empty API response so we should use that:

% terraform apply
aws_ebs_volume.hashi-test: Creating...
  availability_zone: "" => "eu-central-1a"
  encrypted:         "" => "<computed>"
  iops:              "" => "<computed>"
  kms_key_id:        "" => "<computed>"
  size:              "" => "5"
  snapshot_id:       "" => "<computed>"
  tags.%:            "" => "1"
  tags.Name:         "" => "hashi-test"
  type:              "" => "<computed>"
aws_ebs_volume.hashi-test: Still creating... (10s elapsed)
aws_ebs_volume.hashi-test: Creation complete (ID: vol-0746b8a7d4f6ac0b5)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:
[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% 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_ebs_volume.hashi-test: Refreshing state... (ID: vol-0746b8a7d4f6ac0b5)
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

~ aws_ebs_volume.hashi-test
    tags.%:    "0" => "1"
    tags.Name: "" => "hashi-test"

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

Fixes: #927

When we ran the create, we didn't make a call to the API to Describe the
volume, therefore, we were not actually setting the values to state
based on what the API returned. We also only set the Tags to state if
they were not nil. Therefore, the scenario of someone creating a tag
with Terraform, then removing that tag (and thus no tags are left on the
resource) would mean that Terraform didn't see the state drift:

```
[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% terraform apply
aws_ebs_volume.hashi-test: Creating...
  availability_zone: "" => "eu-central-1a"
  encrypted:         "" => "<computed>"
  iops:              "" => "<computed>"
  kms_key_id:        "" => "<computed>"
  size:              "" => "5"
  snapshot_id:       "" => "<computed>"
  tags.%:            "" => "1"
  tags.Name:         "" => "hashi-test"
  type:              "" => "<computed>"
aws_ebs_volume.hashi-test: Still creating... (10s elapsed)
aws_ebs_volume.hashi-test: Creation complete (ID: vol-01133d4a2d74aa55b)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:
[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% 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_ebs_volume.hashi-test: Refreshing state... (ID: vol-01133d4a2d74aa55b)
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, Terraform
doesn't need to do anything.
```

This commit takes care of that but always setting the tags - d.Set handles the empty API response so we should use that:

```
% terraform apply
aws_ebs_volume.hashi-test: Creating...
  availability_zone: "" => "eu-central-1a"
  encrypted:         "" => "<computed>"
  iops:              "" => "<computed>"
  kms_key_id:        "" => "<computed>"
  size:              "" => "5"
  snapshot_id:       "" => "<computed>"
  tags.%:            "" => "1"
  tags.Name:         "" => "hashi-test"
  type:              "" => "<computed>"
aws_ebs_volume.hashi-test: Still creating... (10s elapsed)
aws_ebs_volume.hashi-test: Creation complete (ID: vol-0746b8a7d4f6ac0b5)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:
[stacko@Pauls-MBP:~/Code/terraform-org/terraform-recreations/current-working]
% 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_ebs_volume.hashi-test: Refreshing state... (ID: vol-0746b8a7d4f6ac0b5)
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

~ aws_ebs_volume.hashi-test
    tags.%:    "0" => "1"
    tags.Name: "" => "hashi-test"

Plan: 0 to add, 1 to change, 0 to destroy.
```
@stack72 stack72 added the bug Addresses a defect in current functionality. label Jun 29, 2017
Copy link
Contributor

@grubernaut grubernaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stack72 stack72 merged commit 1450a55 into master Jun 29, 2017
@stack72 stack72 deleted the b-aws-ebs-volume-tags-927 branch June 29, 2017 15:39
@ghost
Copy link

ghost commented Apr 11, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_ebs_volume unable to handle "Name" tag
2 participants