IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
338 stars 662 forks source link

Import ibm_compute_bare_metal does not import required properties #807

Open a7i opened 4 years ago

a7i commented 4 years ago

Terraform Version

Terraform v0.11.14

Affected Resource(s)

Terraform Configuration Files

terraform import ibm_compute_bare_metal.server 792369

Debug Output

ibm_compute_bare_metal.server: Importing from ID "792369"...
ibm_compute_bare_metal.server: Import complete!
  Imported ibm_compute_bare_metal (ID: 792369)
ibm_compute_bare_metal.server: Refreshing state... (ID: 792369)

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.

Expected Behavior

Terraform state should contain the following require properties:

Actual Behavior

Please note that I have redacted some sensitive information in form of <redacted>.

terraform state show ibm_compute_bare_metal.server
id                       = 792369
datacenter               = wdc04
domain                   = <redacted>
global_identifier        = <redacted>
hostname                 = lab-wdc04
hourly_billing           = false
ipv6_enabled             = false
memory                   = 8
network_speed            = 10000
notes                    =
os_reference_code        = UBUNTU_18_64
private_ipv4_address     = 10.149.245.84
private_ipv4_address_id  = 141952818
private_network_only     = false
private_vlan_id          = <redacted>
public_ipv4_address      = <redacted>
public_ipv4_address_id   = <redacted>
public_vlan_id           = <redacted>
redundant_network        = true
redundant_power_supply   = true
secondary_ip_addresses.# = 0
unbonded_network         = false

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a monthly bare-metal server via console
  2. Get the ID from console
  3. Try to import using that ID (e.g. terraform import ibm_compute_bare_metal.server 792369)
  4. Observe that requires fields are not populated in the state
scrossan commented 4 years ago

I have found this myself. I imported a bare metal server and found that, on my next terraform plan terraform wanted to recreate the resource, which I do not want. Here's a gist of the diff: https://gist.github.com/scrossan/a64f4b5a437b6239fe11a1605901d608

So I added the lifecycle block to ignore these attributes:

  lifecycle {
    ignore_changes = [
      "extended_hardware_testing",
      "ipv6_static_enabled",
      "restricted_network"
    ]
  }

My next plan didn't want to recreate the resource but did want to make some changes. Again, here's a gist of the diff: https://gist.github.com/scrossan/6a4aef13ce25e0a94b0df2eb6342602a

As @a7i shows it seems that the IBM provider did not import all of the attributes of my ibm_compute_bare_metal.server:

$ tf state show ibm_compute_bare_metal.server
id                       = <redacted>
datacenter               = tor01
domain                   = <redacted>
global_identifier        = <redacted>
hostname                 = <redacted>
hourly_billing           = false
ipv6_enabled             = false
memory                   = 64
network_speed            = 1000
notes                    =
os_reference_code        = UBUNTU_16_64
private_ipv4_address     = <redacted>
private_ipv4_address_id  = <redacted>
private_network_only     = false
private_vlan_id          = <redacted>
public_ipv4_address      = <redacted>
public_ipv4_address_id   = <redacted>
public_vlan_id           = <redacted>
redundant_network        = true
redundant_power_supply   = true
secondary_ip_addresses.# = 0
unbonded_network         = false

I'm not certain if terraform would attempt to make changes to the resource if I were to run a terraform apply, or would it simply add the attributes in my second diff to my state?

Note I am using v0.19.0 of the IBM provider.

bstoutenburgh commented 4 years ago

Hit this today using 1.2.2 of the provider, terraform 0.12.20.

For the baremetal server I had in question, I just needed the default and saw that replacing null with the default values was going to recreate the resource. I managed to be fine pulling the state down, setting those null values to false and pushing up. Hopefully those attributes could just be pulled from SoftLayer APIs and added to the import list but I haven't gotten around to reading up on SL things yet.