fortinetdev / terraform-provider-fortios

Terraform Fortios provider
https://www.terraform.io/docs/providers/fortios/
Mozilla Public License 2.0
67 stars 50 forks source link

Interfaces not being imported when importing fortios_router_multicast resource #330

Open zippanto opened 2 months ago

zippanto commented 2 months ago

Hi,

When we import multicast router configuration using the command

terraform import fortios_router_multicast.resource_name RouterMulticast

The interface blocks are not being imported. If we then apply it obviously shows the changes and after the successful apply there are no futher changes being shown.

Please advise.

Thanks.

MaxxLiu22 commented 2 months ago

Hi @zippanto ,

Thank you for your question. The block is not imported by default. If you would like to import the block, you need to run export FORTIOS_IMPORT_TABLE"="true" before your import operation. Let me know if that doesn't solve your question.

Thanks, Maxx

zippanto commented 2 months ago

Hi @MaxxLiu22,

I tried that, but unfortunately still experiencing the same issue.

Thanks.

MaxxLiu22 commented 1 month ago

Hi @zippanto ,

Thank you for your reply, how about adding get_all_tables = true in your fortios_router_multicast resource and run export FORTIOS_IMPORT_TABLE="true", then import again, let me know if this can solve your question.

resource "fortios_router_multicast" "labelname" {
  multicast_routing = "disable"
  route_limit       = 2147483647
  route_threshold   = 2147483647
  get_all_tables = true  <------------
}

Thanks, Maxx

zippanto commented 1 month ago

Hi @MaxxLiu22,

It made no difference unfortunately, still seeing the same.

Thanks.

MaxxLiu22 commented 1 month ago

Hi @zippanto ,

That's unusual; it works well for me when I run export FORTIOS_IMPORT_TABLE="true" before the import. Could you please let me know which FOS version and provider version you are using? If you have enabled multi-vdom mode, please ensure that the vdom is defined in the provider. Based on my experience with FOS 7.4.4, the Terraform import interface works successfully, and the Terraform plan tries to delete the naf.test interface.

root@liang:~/terraform/fgt/github#330# export FORTIOS_IMPORT_TABLE="true"
root@liang:~/terraform/fgt/github#330# echo $FORTIOS_IMPORT_TABLE
true
root@liang:~/terraform/fgt/github#330# terraform import fortios_router_multicast.labelname RouterMulticast
fortios_router_multicast.labelname: Importing from ID "RouterMulticast"...
fortios_router_multicast.labelname: Import prepared!
  Prepared fortios_router_multicast for import
fortios_router_multicast.labelname: Refreshing state... [id=RouterMulticast]

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.

root@liang:~/terraform/fgt/github#330# terraform plan
fortios_router_multicast.labelname: Refreshing state... [id=RouterMulticast]

Terraform used the selected providers to generate the following execution plan. Resource actions
are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # fortios_router_multicast.labelname will be updated in-place
  ~ resource "fortios_router_multicast" "labelname" {
      + dynamic_sort_subtable = "false"
      + get_all_tables        = "false"
        id                    = "RouterMulticast"
      + route_threshold       = 2147483647
        # (3 unchanged attributes hidden)

      - interface {
          - bfd                    = "disable" -> null
          - cisco_exclude_genid    = "disable" -> null
          - dr_priority            = 1 -> null
          - hello_holdtime         = 105 -> null
          - hello_interval         = 30 -> null
          - name                   = "naf.test" -> null
          - passive                = "disable" -> null
          - pim_mode               = "sparse-mode" -> null
          - propagation_delay      = 500 -> null
          - rp_candidate           = "disable" -> null
          - rp_candidate_interval  = 60 -> null
          - rp_candidate_priority  = 192 -> null
          - rpf_nbr_fail_back      = "disable" -> null
          - state_refresh_interval = 60 -> null
          - ttl_threshold          = 1 -> null

          - igmp {
              - last_member_query_count    = 2 -> null
              - last_member_query_interval = 1000 -> null
              - query_interval             = 125 -> null
              - query_max_response_time    = 10 -> null
              - query_timeout              = 255 -> null
              - router_alert_check         = "disable" -> null
              - version                    = "3" -> null
            }
        }

        # (1 unchanged block hidden)
    }

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

Thanks, Maxx

zippanto commented 1 month ago

Hi @MaxxLiu22,

FOS version 7.2.8. Not using VDOMs. Please see my outputs below.

Firewall config

FW $ show router multicast
config router multicast
    set multicast-routing enable
    config interface
        edit "A.1111"
            set pim-mode sparse-mode
            config igmp
                set version 2
            end
        next
        edit "B.2222"
            set pim-mode sparse-mode
            config igmp
                set version 2
            end
            set dr-priority 100
        next
    end
end

TF file

resource "fortios_router_multicast" "multicast" {
  get_all_tables = true
  multicast_routing = "enable"

  interface {
      name        = "A.1111"
      pim_mode    = "sparse-mode"
      igmp {
        version = "2"
      }
  }

  interface {
      name        = "B.2222"
      pim_mode    = "sparse-mode"
      dr_priority = "100"
      igmp {
        version = "2"
      }
  }  
}

export, terraform import and terraform plan commands

% export FORTIOS_IMPORT_TABLE="true"
% echo $FORTIOS_IMPORT_TABLE
true
% terraform import fortios_router_multicast.multicast RouterMulticast
fortios_router_multicast.multicast: Importing from ID "RouterMulticast"...
fortios_router_multicast.multicast: Import prepared!
  Prepared fortios_router_multicast for import
fortios_router_multicast.multicast: Refreshing state... [id=RouterMulticast]

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.

% terraform plan                                   
fortios_router_multicast.multicast: Refreshing state... [id=RouterMulticast]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # fortios_router_multicast.multicast will be updated in-place
  ~ resource "fortios_router_multicast" "multicast" {
      + dynamic_sort_subtable = "false"
      + get_all_tables        = "true"
        id                    = "RouterMulticast"
        # (2 unchanged attributes hidden)

      + interface {
          + name     = "A.1111"
          + pim_mode = "sparse-mode"

          + igmp {
              + version = "2"
            }
        }
      + interface {
          + dr_priority = 100
          + name        = "B.2222"
          + pim_mode    = "sparse-mode"

          + igmp {
              + version = "2"
            }
        }

        # (1 unchanged block hidden)
    }

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

Thanks.

MaxxLiu22 commented 1 month ago

Hi @zippanto ,

Thank you for providing this information. I can reproduce that, It appears that the issue is related to the hello-holdtime API argument in the interface block. This argument has a default integer value of 105, but the API returns an empty string, causing a data type inconsistency between the API and Terraform, which results in the import process failing. I have reported this issue to the development team for resolution. In the meantime, could you please manually set the hello-holdtime value to any number such as 110 other than 105 through CLI and attempt the import again? Please let me know if the issue persists.

FGT-VM-103 # config router multicast 

FGT-VM-103 (multicast) # config interface 

FGT-VM-103 (interface) # 
FGT-VM-103 (interface) # edit port1 

FGT-VM-103 (port1) # show
config interface
    edit "port1"
        set pim-mode sparse-mode
    next
end

FGT-VM-103 (port1) # set hello-holdtime 110

FGT-VM-103 (port1) # end

Thanks, Maxx

zippanto commented 1 month ago

Hi @MaxxLiu22,

That's now working as expected, without using FORTIOS_IMPORT_TABLE or get_all_tables.

If you can, please let us know once there is a permanent fix available. I presume this will only be fixed in a future FortiOS release?

Thanks.

MaxxLiu22 commented 1 week ago

Hi @zippanto,

I wanted to let you know that this issue has been resolved in Terraform FOS 1.21.0. Whenever you have a chance, please upgrade to that version, and feel free to reach out if you have any further questions.

Thank you, Maxx