Skip to content

Commit

Permalink
Merge pull request #78 from umich-vci/fix_import
Browse files Browse the repository at this point in the history
Fix import
  • Loading branch information
adarobin authored Mar 26, 2024
2 parents 3cab1ba + 2bd718c commit b4d0bbb
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 58 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.3 (March 26, 2024)

BREAKING CHANGES:
* IDs must be treated as a string so that import works correctly.

## 0.4.2 (March 25, 2024)

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ output "bluecat_config_id" {

### Read-Only

- `id` (Number) Entity identifier
- `id` (String) Entity identifier
- `properties` (String) The properties of the entity as returned by the API (pipe delimited).
2 changes: 1 addition & 1 deletion docs/data-sources/host_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ output "bluecat_host_addresses" {

- `address_ids` (Set of Number) A set of all address ids associated with the host record.
- `addresses` (Set of String) A set of all addresses associated with the host record.
- `id` (Number) Entity identifier
- `id` (String) Entity identifier
- `name` (String) The short name of the host record.
- `parent_id` (Number) The ID of the parent of the host record.
- `parent_type` (String) The type of the parent of the host record.
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ip4_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ output "bluecat_address_mac" {
### Read-Only

- `custom_properties` (Map of String) A map of all custom properties associated with the IPv4 address.
- `id` (Number) IP4 Address identifier
- `id` (String) IP4 Address identifier
- `mac_address` (String) The MAC address associated with the IPv4 address.
- `name` (String) The name assigned to the IPv4 address. This is not related to DNS.
- `properties` (String) The properties of the IPv4 address as returned by the API (pipe delimited).
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ip4_nbr.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ output "bluecat_network_name" {
- `default_view` (Number) The object id of the default DNS View for the network.
- `dns_restrictions` (Set of Number) TODO
- `gateway` (String) The gateway of the IPv4 network.
- `id` (Number) Example identifier
- `id` (String) Example identifier
- `inherit_allow_duplicate_host` (Boolean) Duplicate host names check is inherited.
- `inherit_default_domains` (Boolean) Default domains are inherited.
- `inherit_default_view` (Boolean) The default DNS View is inherited.
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ip4_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Data source to access the attributes of an IPv4 network from a hint based search
- `default_view` (Number) The object id of the default DNS View for the network.
- `dns_restrictions` (Set of Number) The object ids of the DNS restrictions for the network.
- `gateway` (String) The gateway of the IP4Network.
- `id` (Number) The ID assigned to the IP4Network.
- `id` (String) The ID assigned to the IP4Network.
- `inherit_allow_duplicate_host` (Boolean) Duplicate host names check is inherited.
- `inherit_default_domains` (Boolean) Default domains are inherited.
- `inherit_default_view` (Boolean) The default DNS View is inherited.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/host_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ output "bluecat_hostname_fqdn" {

- `absolute_name` (String) The absolute name (fqdn) of the host record.
- `address_ids` (Set of Number) A set of all address ids associated with the host record.
- `id` (Number) Host Record identifier
- `id` (String) Host Record identifier
- `properties` (String) The properties of the host record as returned by the API (pipe delimited).
- `type` (String) The type of the resource.
2 changes: 1 addition & 1 deletion docs/resources/ip4_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ output "allocated_address" {

- `address` (String) The IPv4 address that was allocated.
- `expiry_time` (String) Time that IPv4 address lease expires.
- `id` (Number) IPv4 Address identifier.
- `id` (String) IPv4 Address identifier.
- `lease_time` (String) Time that IPv4 address was leased.
- `location_inherited` (Boolean) The location is inherited.
- `parameter_request_list` (String) Time that IPv4 address lease expires.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/ip4_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ output "bluecat_ip4_network_cidr" {
### Read-Only

- `cidr` (String) The CIDR address of the IPv4 network.
- `id` (Number) IPv4 Network identifier.
- `id` (String) IPv4 Network identifier.
- `location_inherited` (Boolean) The location is inherited.
- `properties` (String) The properties of the resource as returned by the API (pipe delimited).
- `shared_network` (String) The name of the shared network tag associated with the IP4 Network.
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/data_source_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand All @@ -27,7 +28,7 @@ type entityDataSource struct {

// ExampleDataSourceModel describes the data source data model.
type EntityDataSourceModel struct {
Id types.Int64 `tfsdk:"id"`
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
ParentID types.Int64 `tfsdk:"parent_id"`
Expand All @@ -44,7 +45,7 @@ func (d *entityDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
MarkdownDescription: "Data source to access the attributes of a BlueCat entity.",

Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "Entity identifier",
Computed: true,
},
Expand Down Expand Up @@ -126,7 +127,7 @@ func (d *entityDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

data.Id = types.Int64Value(*entity.Id)
data.Id = types.StringValue(strconv.FormatInt(*entity.Id, 10))
data.Properties = types.StringValue(*entity.Properties)

resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_host_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type HostRecordDataSource struct {

// HostRecordDataSourceModel describes the data source data model.
type HostRecordDataSourceModel struct {
ID types.Int64 `tfsdk:"id"`
ID types.String `tfsdk:"id"`
AbsoluteName types.String `tfsdk:"absolute_name"`
Addresses types.Set `tfsdk:"addresses"`
AddressIDs types.Set `tfsdk:"address_ids"`
Expand All @@ -50,7 +50,7 @@ func (d *HostRecordDataSource) Schema(ctx context.Context, req datasource.Schema
MarkdownDescription: "Example data source",

Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "Entity identifier",
Computed: true,
},
Expand Down Expand Up @@ -193,7 +193,7 @@ func (d *HostRecordDataSource) Read(ctx context.Context, req datasource.ReadRequ
return
}

data.ID = types.Int64Value(*hostRecords.Item[matchLocation].Id)
data.ID = types.StringValue(strconv.FormatInt(*hostRecords.Item[matchLocation].Id, 10))
data.Name = types.StringValue(*hostRecords.Item[matchLocation].Name)
data.Properties = types.StringValue(*hostRecords.Item[matchLocation].Properties)
data.Type = types.StringValue(*hostRecords.Item[matchLocation].Type)
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/data_source_ip4_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand All @@ -24,7 +25,7 @@ type IP4AddressDataSource struct {
// IP4AddressDataSourceModel describes the data source data model.
type IP4AddressDataSourceModel struct {
// These are exposed for a generic entity object in bluecat
ID types.Int64 `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
Properties types.String `tfsdk:"properties"`
Expand Down Expand Up @@ -60,7 +61,7 @@ func (d *IP4AddressDataSource) Schema(ctx context.Context, req datasource.Schema
MarkdownDescription: "Data source to access the attributes of an IPv4 address.",

Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "IP4 Address identifier",
Computed: true,
},
Expand Down Expand Up @@ -147,7 +148,7 @@ func (d *IP4AddressDataSource) Read(ctx context.Context, req datasource.ReadRequ
return
}

data.ID = types.Int64PointerValue(ip4Address.Id)
data.ID = types.StringValue(strconv.FormatInt(*ip4Address.Id, 10))
data.Name = types.StringPointerValue(ip4Address.Name)
data.Properties = types.StringPointerValue(ip4Address.Properties)
data.Type = types.StringPointerValue(ip4Address.Type)
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_ip4_nbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IP4NBRDataSource struct {

// IP4NBRDataSourceModel describes the data source data model.
type IP4NBRDataSourceModel struct {
ID types.Int64 `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Address types.String `tfsdk:"address"`
ContainerID types.Int64 `tfsdk:"container_id"`
Type types.String `tfsdk:"type"`
Expand Down Expand Up @@ -69,7 +69,7 @@ func (d *IP4NBRDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
MarkdownDescription: "Data source to access the attributes of an IPv4 network, IPv4 Block, or DHCPv4 Range from an IPv4 address.",

Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "Example identifier",
Computed: true,
},
Expand Down Expand Up @@ -222,7 +222,7 @@ func (d *IP4NBRDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

data.ID = types.Int64PointerValue(ipRange.Id)
data.ID = types.StringValue(strconv.FormatInt(*ipRange.Id, 10))
data.Name = types.StringPointerValue(ipRange.Name)
data.Properties = types.StringPointerValue(ipRange.Properties)
data.Type = types.StringPointerValue(ipRange.Type)
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/data_source_ip4_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand All @@ -25,7 +26,7 @@ type IP4NetworkDataSource struct {
// IP4NetworkDataSourceModel describes the data source data model.
type IP4NetworkDataSourceModel struct {
// These are exposed for a generic entity object in bluecat
ID types.Int64 `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
Properties types.String `tfsdk:"properties"`
Expand Down Expand Up @@ -74,7 +75,7 @@ func (d *IP4NetworkDataSource) Schema(ctx context.Context, req datasource.Schema
MarkdownDescription: "Hint to find the IP4Network",
Required: true,
},
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The ID assigned to the IP4Network.",
Computed: true,
},
Expand Down Expand Up @@ -221,7 +222,7 @@ func (d *IP4NetworkDataSource) Read(ctx context.Context, req datasource.ReadRequ
return
}

data.ID = types.Int64PointerValue(hintResp.Item[0].Id)
data.ID = types.StringValue(strconv.FormatInt(*hintResp.Item[0].Id, 10))

// GetIP4NetworksByHint doesn't seem to return all properties so use the ID returned by it to call GetEntityById
entity, err := client.GetEntityById(*hintResp.Item[0].Id)
Expand Down
39 changes: 28 additions & 11 deletions internal/provider/resource_host_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type HostRecordResource struct {
// HostRecordResourceModel describes the resource data model.
type HostRecordResourceModel struct {
// These are exposed for a generic entity object in bluecat
ID types.Int64 `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
Properties types.String `tfsdk:"properties"`
Expand Down Expand Up @@ -72,11 +72,11 @@ func (r *HostRecordResource) Schema(ctx context.Context, req resource.SchemaRequ

Attributes: map[string]schema.Attribute{
// These are exposed for Entity objects via the API
"id": schema.Int64Attribute{
"id": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Host Record identifier",
PlanModifiers: []planmodifier.Int64{
int64planmodifier.UseStateForUnknown(),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"name": schema.StringAttribute{
Expand Down Expand Up @@ -213,9 +213,9 @@ func (r *HostRecordResource) Create(ctx context.Context, req resource.CreateRequ
return
}

data.ID = types.Int64Value(host)
data.ID = types.StringValue(strconv.FormatInt(host, 10))

entity, err := client.GetEntityById(data.ID.ValueInt64())
entity, err := client.GetEntityById(host)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -269,7 +269,12 @@ func (r *HostRecordResource) Read(ctx context.Context, req resource.ReadRequest,
return
}

id := data.ID.ValueInt64()
id, err := strconv.ParseInt(data.ID.ValueString(), 10, 64)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError("Failed to parse ID", err.Error())
return
}

entity, err := client.GetEntityById(id)
if err != nil {
Expand Down Expand Up @@ -365,23 +370,30 @@ func (r *HostRecordResource) Update(ctx context.Context, req resource.UpdateRequ
}
}

id, err := strconv.ParseInt(data.ID.ValueString(), 10, 64)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError("Failed to parse ID", err.Error())
return
}

tflog.Debug(ctx, fmt.Sprintf("Attempting to update HostRecord with properties: %s", properties))

update := gobam.APIEntity{
Id: data.ID.ValueInt64Pointer(),
Id: &id,
Name: data.Name.ValueStringPointer(),
Properties: &properties,
Type: state.Type.ValueStringPointer(),
}

err := client.Update(&update)
err = client.Update(&update)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError("Host Record Update failed", err.Error())
return
}

entity, err := client.GetEntityById(data.ID.ValueInt64())
entity, err := client.GetEntityById(id)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -431,7 +443,12 @@ func (r *HostRecordResource) Delete(ctx context.Context, req resource.DeleteRequ
return
}

id := data.ID.ValueInt64()
id, err := strconv.ParseInt(data.ID.ValueString(), 10, 64)
if err != nil {
resp.Diagnostics.Append(clientLogout(ctx, &client, mutex)...)
resp.Diagnostics.AddError("Failed to parse ID", err.Error())
return
}

entity, err := client.GetEntityById(id)
if err != nil {
Expand Down
Loading

0 comments on commit b4d0bbb

Please sign in to comment.