Skip to content

Latest commit

 

History

History
62 lines (59 loc) · 2.46 KB

File metadata and controls

62 lines (59 loc) · 2.46 KB

Terraform

  • NOTES:
    • This section depends on Kubernetes and a ~/.kubeconfig from above
    • NodePort was used instead of LoadBalancer for service.type
  • Install terraform via `asdf
    # terraform
    asdf plugin-add terraform
    asdf install terraform latest
  • Add aliases to ~/.bashrc or ~/.zshrc
    # ~/.bashrc
    alias tf='terraform'
    alias tfi='terraform init -backend-config=./state.conf'
    alias tfa='terraform apply'
    alias tfp='terraform plan'
    alias tfpn='terraform plan -refresh=false'
  • Navigate to ./terraform/ and initialize the terraform working directory
    cd terraform/
    tfi
  • Create an execution plan
    tfp
  • Apply/execute the actions from Terraform plan
    tfa
  • Navigate to http://localhost:<port>
    • Port can be found via kubectl
      k get svc   # 80:31942/TCP
  • Tear down deployment
    tf destroy
    • Real-time view of pod removal Real-time view of pod removal

Debugging

  • Verbose logging and redirection to a file

    export TF_LOG="trace"                       # unset via "off"
    export TF_LOG_PATH="$HOME/Downloads/tf.log" # `~` doesn't expand
  • Error: cannot re-use a name that is still in use

    I think I resolved the issue. This is what I did: 1) mv the terraform.tfstate to another name, 2) mv the terraform.tfstate.backup to terraform.tfstate, and 3) run 'terraform refresh' command to confirm the state is synchronized, and 4) run 'terraform apply' to delete/create the resource. I will mark your reply as the answer, as it gives me the clue for solving the issue. Thanks! – ozmhsh Dec 9, 2021 at 4:57

    nginx - Stuck in the partial helm release on Terraform to Kubernetes - Stack Overflow