Git Product home page Git Product logo

Comments (3)

RmMsr avatar RmMsr commented on August 15, 2024 2

Thanks for the extensive debugging. In the meantime we mainly use staging environments and keep services active all the time. So the issue does not surface any more. But if it happens I can come back to the examples above. Closing the issue now as it's minor and not blocking anything.

from terraform-provider-fastly.

Integralist avatar Integralist commented on August 15, 2024

👋🏻 Hi @RmMsr

Thanks for opening this issue!

I've created an internal ticket to track this and will report back once I've had a chance to investigate.

from terraform-provider-fastly.

Integralist avatar Integralist commented on August 15, 2024

👋 Hi @RmMsr

Thanks for your patience. I've only just started looking into this and I can replicate the issue (e.g. Terraform state getting out-of-sync with the real-world) and I believe I'm able to resolve the issue and get the state back in-sync.

The summary of the steps I took (and seems I needed to run terraform apply -refresh-only twice, although at this point in time I'm not entirely sure why) were...

# deactivate service
fastly service-version deactivate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest

# get terraform state in-sync with deactivated service (e.g. active/clone is 0/0)
terraform apply -refresh-only

# get terraform state to track correct clone version (e.g. active/clone is 0/1)
terraform apply -refresh-only

# reactive the service (active version will increase by 1)
fastly service-version activate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest --autoclone

# get terraform state back in-sync (e.g. active/clone is 2/2)
terraform apply -refresh-only

Terraform doesn't like when resources it manages are modified outside of Terraform. So I always like to recommend that customers avoid patterns that require them to modify a resource outside of Terraform.

Below is the complete testing flow I took, and hopefully will give a complete view of what I was seeing and how I reached the final conclusion/resolution...

# create service
terraform apply

# state shows active/clone is 1/1
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# deactivate service
fastly service-version deactivate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest

# show active/clone changing from one to zero
terraform plan -refresh-only

# state shows active/clone is 1/1
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# apply state refresh
terraform apply -refresh-only

# state shows active/clone is 0/0
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# show 'clone version' changing from zero back to one
terraform plan -refresh-only

# apply state refresh
terraform apply -refresh-only

# state shows active/clone is 0/1
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# re-activate the service (active version will become 2)
fastly service-version activate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest --autoclone

# check plan shows no changes
terraform plan

# state shows active/clone is 0/1
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# shows active/clone is 2/2 (i.e. getting back in-sync)
terraform plan -refresh-only

# apply state refresh
terraform apply -refresh-only

# state shows active/clone is 2/2
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# make a config change and apply
terraform apply

# state shows active/clone is 3/3
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

# deactivate service
fastly service-version deactivate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest

# reactive the service (active version will become 4)
fastly service-version activate --service-id=$(fastly service list --json | jq -r 'map(select(.Name == "testing-tf-provider-reactivation-bug")) | .[].ID') --version latest --autoclone

# get terraform state back in-sync (shows change from version 3 to 4)
terraform plan -refresh-only

# apply state refresh
terraform apply -refresh-only

# state shows active/clone is 4/4
cat terraform.tfstate | jq '.resources[].instances[].attributes | "active: \(.active_version), clone: \(.cloned_version)"'

from terraform-provider-fastly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.