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

Imported BootVolume's sourceDetails is null causing unwanted replace #714

Open
JakubKoralewski opened this issue Feb 6, 2025 · 2 comments
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@JakubKoralewski
Copy link

JakubKoralewski commented Feb 6, 2025

Describe what happened

I import an existing BootVolume into Pulumi, I don't (want to) change anything on the boot volume, just import as-is, but when I run pulumi up it wants to replace my boot volume. I think that's a bug as it will delete my data.

I import a boot volume:

pulumi import oci:Core/bootVolume:BootVolume code-server-boot-volume ocid1.bootvolume.oc1.eu-amsterdam-1.id

After importing a boot volume I get this message (full logs of pulumi import in logs section):

Diagnostics:
  oci:Core:BootVolume (code-server-boot-volume):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `oci` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: oci:Core/bootVolume:BootVolume resource 'code-server-boot-volume' has a problem: Missing required argument. The argument "source_details" is required, but no definition was found.. Examine values at 'code-server-boot-volume.sourceDetails'.

You can see the imported sourceDetails is malformed:

        sourceDetails     : <null>

And the pulumi code it tells me to use has malformed types:

    sourceDetails: {
        type: "",
    },

I get an error that type needs to be either of bootVolume, bootVolumeBackup, etc.

Now when I do pulumi up I get this error (due to the sourceDetails issues above):

jakubkoralewski@Er codeserver-2 % pulumi up -s bug-repro
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (bug-repro):
     Type                    Name                     Plan     Info
     pulumi:pulumi:Stack     codeserver-2-bug-repro            
     └─ oci:Core:BootVolume  code-server-boot-volume           1 error

Diagnostics:
  oci:Core:BootVolume (code-server-boot-volume):
    error: oci:Core/bootVolume:BootVolume resource 'code-server-boot-volume' has a problem: expected source_details.0.type to be one of ["bootVolume" "bootVolumeBackup" "bootVolumeBackupDelta" "bootVolumeReplica"], got . Examine values at 'code-server-boot-volume.sourceDetails.type'.

I tried setting it to a bootVolume since that's what it is:

        sourceDetails: {
            type: "bootVolume",
        },

Then pulumi up wants to replace my volume:

jakubkoralewski@Er codeserver-2 % pulumi up -s bug-repro
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (bug-repro):
     Type                    Name                     Plan        Info
     pulumi:pulumi:Stack     codeserver-2-bug-repro               1 error
 +-  └─ oci:Core:BootVolume  code-server-boot-volume  replace     [diff: +sourceDeta

Diagnostics:
  pulumi:pulumi:Stack (codeserver-2-bug-repro):
    error: preview failed

  oci:Core:BootVolume (code-server-boot-volume):
    error: unable to replace resource "urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume"
    as it is currently marked for protection. To unprotect the resource, remove the `protect` flag from the resource in your Pulumi program and run `pulumi up`

If I remove the {protect:true} the details gives me this output:

jakubkoralewski@Er codeserver-2 % pulumi up -s bug-repro
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing update (bug-repro):
     Type                    Name                     Plan        Info
     pulumi:pulumi:Stack     codeserver-2-bug-repro               
 +-  └─ oci:Core:BootVolume  code-server-boot-volume  replace     [diff: +sourceDetails~sourceDetails]

Resources:
    +-1 to replace
    1 unchanged

Do you want to perform this update? details
  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:bug-repro::codeserver-2::pulumi:pulumi:Stack::codeserver-2-bug-repro]
    ++oci:Core/bootVolume:BootVolume: (create-replacement) 🔓
        [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]
        [urn=urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume]
        [provider=urn:pulumi:bug-repro::codeserver-2::pulumi:providers:oci::default_2_23_0::151d1dd8-46f3-4fdb-9ec2-19cda3f713bd]
      + sourceDetails: {
          + type      : "bootVolume"
        }
      + sourceDetails: {
          + type      : "bootVolume"
        }
    +-oci:Core/bootVolume:BootVolume: (replace) 🔓
        [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]
        [urn=urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume]
        [provider=urn:pulumi:bug-repro::codeserver-2::pulumi:providers:oci::default_2_23_0::151d1dd8-46f3-4fdb-9ec2-19cda3f713bd]
      + sourceDetails: {
          + type      : "bootVolume"
        }
      + sourceDetails: {
          + type      : "bootVolume"
        }
    --oci:Core/bootVolume:BootVolume: (delete-replaced) 🔒
        [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]
        [urn=urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume]
        [provider=urn:pulumi:bug-repro::codeserver-2::pulumi:providers:oci::default_2_23_0::151d1dd8-46f3-4fdb-9ec2-19cda3f713bd]

Do you want to perform this update?  [Use arrows to move, type to filter]
  yes
> no
  details

I don't understand this output tbh.

Sample program

It's auto-generated after the pulumi import but here you go:

import * as oci from "@pulumi/oci";

export = async () => {
    const code_server_boot_volume = new oci.core.BootVolume("code-server-boot-volume", {
        autotunePolicies: [{
            autotuneType: "DETACHED_VOLUME",
        }],
        availabilityDomain: "fkYL:eu-amsterdam-1-AD-1",
        compartmentId: "ocid1.tenancy.oc1..id",
        definedTags: {
            "Oracle-Tags.CreatedBy": "oracleidentitycloudservice/[email protected]",
            "Oracle-Tags.CreatedOn": "2021-12-14T18:45:26.894Z",
        },
        displayName: "code-server (Boot Volume)",
        isAutoTuneEnabled: true,
        sizeInGbs: "50",
        sourceDetails: {
            type: "",
        },
        vpusPerGb: "10",
    }, {protect:true});
}

Log output

Full output of pulumi import:

jakubkoralewski@Er codeserver-2 % pulumi import oci:Core/bootVolume:BootVolume code-server-boot-volume ocid1.bootvolume.oc1.eu-amsterdam-1.abqw2ljr2o4x47mzmdhcqzkejsifmk4v3qqim3pnaz53k3i5mhetg55clxla
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
Previewing import (bug-repro):
     Type                    Name                     Plan       Info
 +   pulumi:pulumi:Stack     codeserver-2-bug-repro   create     
 =   └─ oci:Core:BootVolume  code-server-boot-volume  import     2 warnings

Diagnostics:
  oci:Core:BootVolume (code-server-boot-volume):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `oci` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: oci:Core/bootVolume:BootVolume resource 'code-server-boot-volume' has a problem: Missing required argument. The argument "source_details" is required, but no definition was found.. Examine values at 'code-server-boot-volume.sourceDetails'.

Resources:
    + 1 to create
    = 1 to import
    2 changes

Do you want to perform this import? details
+ pulumi:pulumi:Stack: (create)
    [urn=urn:pulumi:bug-repro::codeserver-2::pulumi:pulumi:Stack::codeserver-2-bug-repro]
    = oci:Core/bootVolume:BootVolume: (import) 🔒
        [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]
        [urn=urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume]
        [provider=urn:pulumi:bug-repro::codeserver-2::pulumi:providers:oci::default_2_23_0::04da6b54-80e4-46f7-96ec-b56ff0331ba9]
        autotunePolicies  : [
            [0]: {
                autotuneType: "DETACHED_VOLUME"
            }
        ]
        availabilityDomain: "fkYL:eu-amsterdam-1-AD-1"
        compartmentId     : "ocid1.tenancy.oc1..id"
        definedTags       : {
            Oracle-Tags.CreatedBy: "oracleidentitycloudservice/[email protected]"
            Oracle-Tags.CreatedOn: "2021-12-14T18:45:26.894Z"
        }
        displayName       : "code-server (Boot Volume)"
        isAutoTuneEnabled : true
        sizeInGbs         : "50"
        sourceDetails     : <null>
        vpusPerGb         : "10"

Do you want to perform this import? yes
Importing (bug-repro):
     Type                    Name                     Status               Info
 +   pulumi:pulumi:Stack     codeserver-2-bug-repro   created              
 =   └─ oci:Core:BootVolume  code-server-boot-volume  imported (0.42s)     2 warning

Diagnostics:
  oci:Core:BootVolume (code-server-boot-volume):
    warning: One or more imported inputs failed to validate. This is almost certainly a bug in the `oci` provider. The import will still proceed, but you will need to edit the generated code after copying it into your program.
    warning: oci:Core/bootVolume:BootVolume resource 'code-server-boot-volume' has a problem: Missing required argument. The argument "source_details" is required, but no definition was found.. Examine values at 'code-server-boot-volume.sourceDetails'.

Resources:
    + 1 created
    = 1 imported
    2 changes

Duration: 2s

Please copy the following code into your Pulumi application. Not doing so
will cause Pulumi to report that an update will happen on the next update command.

Please note that the imported resources are marked as protected. To destroy them
you will need to remove the `protect` option and run `pulumi update` *before*
the destroy will take effect.

import * as pulumi from "@pulumi/pulumi";
import * as oci from "@pulumi/oci";

const code_server_boot_volume = new oci.core.BootVolume("code-server-boot-volume", {
    autotunePolicies: [{
        autotuneType: "DETACHED_VOLUME",
    }],
    availabilityDomain: "fkYL:eu-amsterdam-1-AD-1",
    compartmentId: "ocid1.tenancy.oc1..id",
    definedTags: {
        "Oracle-Tags.CreatedBy": "oracleidentitycloudservice/[email protected]",
        "Oracle-Tags.CreatedOn": "2021-12-14T18:45:26.894Z",
    },
    displayName: "code-server (Boot Volume)",
    isAutoTuneEnabled: true,
    sizeInGbs: "50",
    sourceDetails: {
        type: "",
    },
    vpusPerGb: "10",
}, {
    protect: true,
});

Affected Resource(s)

BootVolume

Output of pulumi about

jakubkoralewski@Er codeserver-2 % pulumi about
Enter your passphrase to unlock config/secrets
    (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):  
Enter your passphrase to unlock config/secrets
CLI          
Version      3.136.1
Go Version   go1.23.2
Go Compiler  gc

Plugins
KIND      NAME    VERSION
language  nodejs  unknown
resource  oci     2.23.0

Host     
OS       darwin
Version  14.5
Arch     arm64

This project is written in nodejs: executable='/usr/local/bin/node' version='v19.6.1'

Current Stack: organization/codeserver-2/bug-repro

TYPE                            URN
pulumi:pulumi:Stack             urn:pulumi:bug-repro::codeserver-2::pulumi:pulumi:Stack::codeserver-2-bug-repro
pulumi:providers:oci            urn:pulumi:bug-repro::codeserver-2::pulumi:providers:oci::default_2_23_0
oci:Core/bootVolume:BootVolume  urn:pulumi:bug-repro::codeserver-2::oci:Core/bootVolume:BootVolume::code-server-boot-volume


Found no pending operations associated with bug-repro

Backend        
Name           Er.local
URL            file://./stack
User           jakubkoralewski
Organizations  
Token type     personal

Pulumi locates its logs in /var/folders/7f/rdn7ymps56576nz1c2cn1bth0000gn/T/ by default
warning: Failed to get information about the Pulumi program's dependencies: no package-lock.json or yarn.lock file found (searching upwards from /Users/jakubkoralewski/Projects/codeserver-2)
jakubkoralewski@Er codeserver-2 % 

Additional context

In the meantime, should I edit the stack state manually somehow?
EDIT: Yes, added {"type": "bootVolume"} to both "inputs" and "outputs" in the state entry of the boot volume, now it doesn't want to replace anymore

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).

@JakubKoralewski JakubKoralewski added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Feb 6, 2025
@corymhall
Copy link

@JakubKoralewski thanks for reporting this issue. It looks like this is probably an issue with the upstream provider as well. If you could try to reproduce this in Terraform that would help us know for sure.

My hunch is that this is caused by the Terraform importer being best effort. I am assuming that the sourceDetails in the cloud is empty so when it reads the cloud for an import it populates it as nil. This will fail the property validators which require this value to be set.

The workaround that you mentioned where you edit the state is a good workaround for this.

@corymhall corymhall removed the needs-triage Needs attention from the triage team label Feb 6, 2025
@JakubKoralewski
Copy link
Author

I don't know terraform that well, but it looks to me like the same exact issue:

The output of terraform show which I copied to main.tf had no source_details, and when I added it manually I got the output: oci_core_boot_volume.code_server_boot_volume must be replaced, because source_details { # forces replacement.

Full logs here:

jakubkoralewski@Er codeserver-2-tf-gh-repro % terraform import oci_core_boot_volume.code_server_boot_volume ocid1.bootvolume.oc1.eu-amsterdam-1.id
oci_core_boot_volume.code_server_boot_volume: Importing from ID "ocid1.bootvolume.oc1.eu-amsterdam-1.id"...
oci_core_boot_volume.code_server_boot_volume: Import prepared!
  Prepared oci_core_boot_volume for import
oci_core_boot_volume.code_server_boot_volume: Refreshing state... [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
jakubkoralewski@Er codeserver-2-tf-gh-repro % terraform plan
oci_core_boot_volume.code_server_boot_volume: Refreshing state... [id=ocid1.bootvolume.oc1.eu-amsterdam-1.id]

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # oci_core_boot_volume.code_server_boot_volume must be replaced
-/+ resource "oci_core_boot_volume" "code_server_boot_volume" {
      ~ auto_tuned_vpus_per_gb     = "10" -> (known after apply)
      + backup_policy_id           = (known after apply)
      + cluster_placement_group_id = (known after apply)
      ~ freeform_tags              = {} -> (known after apply)
      ~ id                         = "ocid1.bootvolume.oc1.eu-amsterdam-1.id" -> (known after apply)
      ~ image_id                   = "ocid1.image.oc1.eu-amsterdam-1.id" -> (known after apply)
      ~ is_auto_tune_enabled       = true -> (known after apply)
      ~ is_hydrated                = true -> (known after apply)
      + kms_key_id                 = (known after apply)
      ~ size_in_mbs                = "51200" -> (known after apply)
      ~ state                      = "AVAILABLE" -> (known after apply)
      ~ system_tags                = {
          - "orcl-cloud.free-tier-retained" = "true"
        } -> (known after apply)
      ~ time_created               = "2021-12-14 18:45:30.188 +0000 UTC" -> (known after apply)
      + volume_group_id            = (known after apply)
      + xrc_kms_key_id             = (known after apply)
        # (6 unchanged attributes hidden)

      ~ autotune_policies {
          + max_vpus_per_gb = (known after apply)
            # (1 unchanged attribute hidden)
        }

      ~ boot_volume_replicas (known after apply)

      + source_details { # forces replacement
          + type = "bootVolume" # forces replacement
        }
    }

Plan: 1 to add, 0 to change, 1 to destroy.

──────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

main.tf

resource "oci_core_boot_volume" "code_server_boot_volume" {
  availability_domain = "fkYL:eu-amsterdam-1-AD-1"
  compartment_id      = "ocid1.tenancy.oc1..id"
  defined_tags = {
    "Oracle-Tags.CreatedBy" = "oracleidentitycloudservice/[email protected]"
    "Oracle-Tags.CreatedOn" = "2021-12-14T18:45:26.894Z"
  }
  display_name  = "code-server (Boot Volume)"
  freeform_tags = {}
  size_in_gbs   = "50"
  vpus_per_gb   = "10"
  source_details {
    type = "bootVolume"
  }

  autotune_policies {
    autotune_type   = "DETACHED_VOLUME"
    max_vpus_per_gb = null
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants