You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've implemented this code in resource_ip_firewall_rule.go that worked for us:
func (r *ipFirewallRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
splits := strings.Split(req.ID, "/")
if len(splits) < 3 {
resp.Diagnostics.AddError("Given ID is malformed", "ID must be formatted like the following: <ip>/<ipOnFirewall>/<sequence>")
return
}
ip := splits[0]
ipOnFirewall := splits[1]
sequence, err := strconv.ParseFloat(splits[2], 64)
if err != nil {
resp.Diagnostics.AddError("Given firewall sequence number is malformed", "Sequence must be a numeric value")
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("ip"), ip)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("ip_on_firewall"), ipOnFirewall)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("sequence"), sequence)...)
}
then I had to edit the Read function to read the DestinationPort from DestinationPortDesc (it might probably need to do the same forse sourcePort and/or other fields):
if strings.HasPrefix(responseData.DestinationPortDesc.ValueString(), "eq ") {
port := strings.TrimPrefix(responseData.DestinationPortDesc.ValueString(), "eq ")
portNumber, err := (strconv.ParseInt(port, 10, 64))
if err == nil {
responseData.DestinationPort = ovhtypes.NewTfInt64Value(portNumber)
}
}
responseData.MergeWith(&data)
The text was updated successfully, but these errors were encountered:
Description
When migrating to terraform it would be nice to import firewall rules to avoid having to delete and recreate them
Affected Resource(s) and/or Data Source(s)
Potential Terraform Configuration
Something like this:
Additional context
I've implemented this code in
resource_ip_firewall_rule.go
that worked for us:then I had to edit the
Read
function to read the DestinationPort from DestinationPortDesc (it might probably need to do the same forse sourcePort and/or other fields):The text was updated successfully, but these errors were encountered: