Troubleshooting
Ada beberapa kejadian disaat melakukan terraform apply kita mengalami beberapa Error, dan berikut saya kumpulkan error-error yang saya dapatkan:
ERROR 1:
Error: A resource with the ID "/subscriptions/cacd41b5-0500-4c1b-840b-13405b6e5b93/resourceGroups/rg-wid-research/providers/Microsoft.DBforPostgreSQL/flexibleServers/wid-postgres-db" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_postgresql_flexible_server" for more information.
│
│ with azurerm_postgresql_flexible_server.postgresql,
│ on postgresql.tf line 1, in resource "azurerm_postgresql_flexible_server" "postgresql":
│ 1: resource "azurerm_postgresql_flexible_server" "postgresql" {
Solusi & Penjelasan
Error ini muncul karena resource PostgreSQL Flexible Server dengan nama wid-postgres-db sudah ada di Azure, tetapi belum tercatat di state file Terraform Anda.
Agar Terraform bisa mengelola resource ini, Anda harus import resource tersebut ke dalam state.
Jalankan perintah berikut di terminal Anda:
terraform import azurerm_postgresql_flexible_server.postgresql /subscriptions/cacd41b5-0500-4c1b-840b-13405b6e5b93/resourceGroups/rg-wid-research/providers/Microsoft.DBforPostgreSQL/flexibleServers/wid-postgres-db
Setelah Import
- Jalankan
terraform planuntuk memastikan konfigurasi di file.tfsudah sesuai dengan resource yang ada di Azure. - Jika ada perbedaan, sesuaikan file
.tfatau resource di Azure agar konsisten. - Setelah itu, Anda bisa melanjutkan
terraform applyseperti biasa.
Catatan:
- Jangan hapus resource langsung dari Azure Portal tanpa menghapusnya dari state Terraform, agar tidak terjadi drift.
- Jika ingin menghapus resource, lakukan dengan
terraform destroysetelah resource sudah ter-import ke state.
No Comments