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

Replacing a resource which is attached to a powered-on server causes server to be off and on multiple times #181

Open
nvthongswansea opened this issue Sep 6, 2021 · 1 comment
Assignees

Comments

@nvthongswansea
Copy link
Member

Replace a resource that is attached to a server causes the server to be turned off and turned on twice. This behavior takes longer time than just shut down and turn on the server only one time.

  • Reproduce the issue:
  1. Do terraform apply:
resource "gridscale_ipv4" "foo" {
  name   = "ip-test"
}
resource "gridscale_server" "foo" {
  name   = "test"
  cores = 2
  memory = 2
  power = true
  ipv4 = gridscale_ipv4.foo.id
}
  1. Replace ipv4 resource foo with foo1, do terraform apply:
resource "gridscale_ipv4" "foo1" {
  name   = "ip-test"
}
resource "gridscale_server" "foo" {
  name   = "test"
  cores = 2
  memory = 2
  power = true
  ipv4 = gridscale_ipv4.foo1.id
}
  • Expected behavior: the server foo will be turned off to remove the attached IPv4 foo and to attach a new IPv4 foo1. Then, it is turned on afterward.

  • Current behavior: the server foo will be turned off to remove the attached IPv4 foo. Then, it gets turned on and off again. IPv4 is attached to the server and the server is turned on.

@nvthongswansea nvthongswansea self-assigned this Sep 6, 2021
@nvthongswansea nvthongswansea changed the title Replacing a resource which is attached to a powered-on server causes server to be off and on multiple time Replacing a resource which is attached to a powered-on server causes server to be off and on multiple times Sep 6, 2021
@nvthongswansea
Copy link
Member Author

The reason why the issue happens is because the deletion of ipv4 foo is executed first (which requires the server to be off) and then the change in server foo (which also requires the server to be off) is applied. If terraform executes them simultaneously, this issue does not appear (because gs terraform provider does have ability to handle concurrent server operations). I've found out why the change in the server foo has to wait for the deletion of the ipv4 foo to finish:

  1. If you take a look at the change in the server foo, there is a line ipv4 = gridscale_ipv4.foo1.id telling the dependency of the server and a new ipv4 foo1. That implies, the new ipv4 foo1 needs to be created before applying the change to the server.
  2. As a result, terraform decides to destroy the ipv4 foo and create the new ipv4 foo1 simultaneously. After finishing those two actions, it will apply the change in the server.

Note: Destroying the ipv4 foo will turn off the server foo, and turn on the server afterward (since the ipv4 foo is attached to the server foo). Changing ipv4 of a server also does those steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant