Skip to content

How do I create objects that have relations with other objects? #197

@fbreckle

Description

@fbreckle

Hi,

I maintain a fork of the old (openapi 2) go-netbox at https://github.com/fbreckle/go-netbox. I specifically, and exclusively, use that library to support my terraform provider at https://github.com/e-breuninger/terraform-provider-netbox.

Since I am not really a fan of backporting the (painfully frequent) breaking api changes to my go-netbox fork, I plan to eventually migrate back to this official client.

As I planned to look at the 4.2 changes today, I figured I might as well check how a migration to this client could work by implementing the netbox_site terraform resource. Specifically, a site has a foreign-key relation to region, meaning I usually pass a region ID to go-netbox when creating the site. The region ID is an int64.

How does this work in this new client? The DcimSitesCreate function gets its values from a WritableSiteRequest. What I do not understand is how I am supposed to fill out the WritableSiteRequest object. In our example, region, it needs a NullableBriefRegionRequest. But that in turn is made from a name and slug, not by an ID.

I looked around the models and it seems this is not an issue specific to the Site object.

Basically, what I am asking is:

Can anyone provide a code example for the following workflow?

  1. Create region, save ID
  2. Create site where the region is set to the previously created region by ID

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions