softlayer / terraform-provider-softlayer

a Terraform (http://terraform.io) provider for interacting with SoftLayer (https://www.softlayer.com)
Mozilla Public License 2.0
40 stars 26 forks source link

Management of custom baremetal builds #143

Closed jvrplmlmn closed 7 years ago

jvrplmlmn commented 7 years ago

Looking at the documentation for the softlayer_bare_metal resource, I see that one of the required fields is fixed_config_preset.

Does this mean that we can only manage baremetals with a configuration preset using this resource?

My use case: importing existing custom baremetal servers, defining them with the softlayer_bare_metal resource, and being able to reference values from this baremetals from other Terraform resources.

Thanks 😃

athak commented 7 years ago

We have managed to import existing baremetal server resources into our config via state surgery and passing an empty string to fixed_config_preset. We wrote a small script that queries the SL API and formats the JSON output to TF state.

renier commented 7 years ago

Hi, yes, basically the bare metal presets are the only ones fully supported. There is already an issue (#18) under which this should be fixed (support for custom config bare metals)

jvrplmlmn commented 7 years ago

We have managed to import existing baremetal server resources into our config via state surgery and passing an empty string to fixed_config_preset. We wrote a small script that queries the SL API and formats the JSON output to TF state.

@athak Any chance that you could share the script?

Hi, yes, basically the bare metal presets are the only ones fully supported. There is already an issue (#18) under which this should be fixed (support for custom config bare metals)

Thanks @renier, I've subscribed to that issue.

athak commented 7 years ago

@jvrplmlmn sorry didn't see this before. Can't share the whole script but basically we query the API with curl to https://api.service.softlayer.com/rest/v3/SoftLayer_Hardware/[server_id].json?objectMask=[mask] where mask is:

'id;hostname;domain;primaryIpAddress;primaryBackendIpAddress;privateNetworkOnlyFlag;userData.value;tagReferences.id;tagReferences.tag.name;hourlyBillingFlag;datacenter.id;datacenter.name;datacenter.longName;primaryNetworkComponent.networkVlan.id;primaryNetworkComponent.networkVlan.primaryRouter;primaryNetworkComponent.networkVlan.vlanNumber;primaryNetworkComponent.maxSpeed;primaryBackendNetworkComponent.networkVlan.id;primaryBackendNetworkComponent.networkVlan.primaryRouter;primaryBackendNetworkComponent.networkVlan.vlanNumber;primaryBackendNetworkComponent.maxSpeed;fixedConfigurationPreset.keyName;operatingSystemReferenceCode'

and then pipe the output to jq:

jq -S '{
  "type": "softlayer_bare_metal",
  "depends_on": [],
  "primary": {
    "id": .id | tostring,
    "attributes": {
      "datacenter": .datacenter.name,
      "domain": .domain,
      "fixed_config_preset": .fixedConfigurationPreset.keyName,
      "hostname": .hostname,
      "hourly_billing": .hourlyBillingFlag | tostring,
      "id": .id | tostring,
      "network_speed": .primaryBackendNetworkComponent.maxSpeed | tostring,
      "os_reference_code": .operatingSystemReferenceCode,
      "private_ipv4_address": .primaryBackendIpAddress,
      "private_network_only": .privateNetworkOnlyFlag | tostring,
      "public_ipv4_address": .primaryIpAddress
    },
    "meta": {},
    "tainted": false
  },
  "deposed": [],
  "provider": ""
}'

We then inject the resulting json fragment to the state under the corresponing module resources. Hope it helps!