pulumi / pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Apache License 2.0
183 stars 53 forks source link

Cannot delete GCP Cloud SQL Instance #1545

Open moulip opened 10 months ago

moulip commented 10 months ago

What happened?

Performing destroy operation and pulumi keeps throwing this error:

Error, failed to delete instance because deletion_protection is set to true. Set it to false to proceed with instance deletion

the deletion_protection_enabled is set to False and the Delete button is available in GCP Portal.

Example

database = gcp.sql.DatabaseInstance("amdatabase",
                opts = pulumi.ResourceOptions(
                    depends_on= [
                        db_ip_reserved_range,
                        private_network_con,
                    ]
                ),
              name = f"{PROJECT_NAME}-amdatabase",
              database_version = "MYSQL_8_0",
              root_password = DB_ROOT_PASSWORD,
              settings = gcp.sql.DatabaseInstanceSettingsArgs(
                  tier = DB_MACHINE_TYPE,
                  availability_type = "ZONAL",
                  edition = "ENTERPRISE",
                  deletion_protection_enabled = False,
                  ip_configuration = gcp.sql.
                  DatabaseInstanceSettingsIpConfigurationArgs(
                      private_network = vpc_network.id,
                      ipv4_enabled = False,
                      enable_private_path_for_google_cloud_services = True
                ),
              )
)

Output of pulumi about

CLI          
Version      3.102.0
Go Version   go1.21.5
Go Compiler  gc

Plugins
NAME    VERSION
gcp     7.5.0
python  unknown

Host     
OS       debian
Version  trixie/sid
Arch     x86_64

This project is written in python: executable='/home/julien/Documents/developpement/spros/pulumi/cloud-infra/bastion4gcp/venv/bin/python3' version='3.11.7'

Current Stack: ***/bastion4gcp/dev

TYPE                                         URN
pulumi:pulumi:Stack                          urn:pulumi:dev::bastion4gcp::pulumi:pulumi:Stack::bastion4gcp-dev
pulumi:providers:gcp                         urn:pulumi:dev::bastion4gcp::pulumi:providers:gcp::default
pulumi:providers:gcp                         urn:pulumi:dev::bastion4gcp::pulumi:providers:gcp::default_7_5_0
gcp:compute/address:Address                  urn:pulumi:dev::bastion4gcp::gcp:compute/address:Address::jumpserverpubip
gcp:compute/network:Network                  urn:pulumi:dev::bastion4gcp::gcp:compute/network:Network::vpc4Bastion
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::jumpServerSubnet
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::BastionSubnet1
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::BastionSubnet2
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::AmSubnet1
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::AmSubnet2
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::LbSubnet
gcp:compute/subnetwork:Subnetwork            urn:pulumi:dev::bastion4gcp::gcp:compute/subnetwork:Subnetwork::DbSubnet
gcp:compute/globalAddress:GlobalAddress      urn:pulumi:dev::bastion4gcp::gcp:compute/globalAddress:GlobalAddress::DbIpRange
gcp:compute/instance:Instance                urn:pulumi:dev::bastion4gcp::gcp:compute/instance:Instance::JumpServer
gcp:compute/instance:Instance                urn:pulumi:dev::bastion4gcp::gcp:compute/instance:Instance::Bastion1
gcp:compute/instance:Instance                urn:pulumi:dev::bastion4gcp::gcp:compute/instance:Instance::Bastion2
gcp:compute/instance:Instance                urn:pulumi:dev::bastion4gcp::gcp:compute/instance:Instance::accessmanager1
gcp:compute/instance:Instance                urn:pulumi:dev::bastion4gcp::gcp:compute/instance:Instance::accessmanager2
gcp:servicenetworking/connection:Connection  urn:pulumi:dev::bastion4gcp::gcp:servicenetworking/connection:Connection::DbPrivateConnection
gcp:sql/databaseInstance:DatabaseInstance    urn:pulumi:dev::bastion4gcp::gcp:sql/databaseInstance:DatabaseInstance::amdatabase

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/****
User           ***
Organizations  ***
Token type     personal

Dependencies:
NAME        VERSION
pip         23.3.2
pulumi_gcp  7.5.0
setuptools  69.0.3
wheel       0.42.0

Pulumi locates its logs in /tmp by default

Additional context

I have to delete manually the DB from GCP Portal and then edit the pulumi state to remove the DB URN.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

iwahbe commented 10 months ago

Hey @moulip. I'm sorry you're having this problem. Just to confirm, have you run pulumi up with deletion_protection_enabled = False before running pulumi destroy?

moulip commented 10 months ago

Hi @iwahbe, in fact the DB is created with deletion_protection_enabled = False. And checking in the portal the protection is actually disabled.

iwahbe commented 9 months ago

Thanks for confirming.

rshade commented 3 days ago

@moulip can you try setting the delete_protection that is outside the settings block like this:

database = gcp.sql.DatabaseInstance(
    "amdatabase",
    name=f"{PROJECT_NAME}-amdatabase",
    database_version="MYSQL_8_0",
    root_password=DB_ROOT_PASSWORD,
    region="us-central1",
    deletion_protection=False,
    settings=gcp.sql.DatabaseInstanceSettingsArgs(
        tier=DB_MACHINE_TYPE,
        availability_type="ZONAL",
        edition="ENTERPRISE",
        # deletion_protection_enabled=False,
    ),
)