|
| 1 | +package producerimagesharegroup |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" |
| 5 | + "github.com/hashicorp/terraform-plugin-framework/diag" |
| 6 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 7 | + "github.com/linode/linodego" |
| 8 | + "github.com/linode/terraform-provider-linode/v3/linode/helper" |
| 9 | +) |
| 10 | + |
| 11 | +type ResourceModel struct { |
| 12 | + ID types.Int64 `tfsdk:"id"` |
| 13 | + UUID types.String `tfsdk:"uuid"` |
| 14 | + Label types.String `tfsdk:"label"` |
| 15 | + Description types.String `tfsdk:"description"` |
| 16 | + IsSuspended types.Bool `tfsdk:"is_suspended"` |
| 17 | + ImagesCount types.Int64 `tfsdk:"images_count"` |
| 18 | + MembersCount types.Int64 `tfsdk:"members_count"` |
| 19 | + Created timetypes.RFC3339 `tfsdk:"created"` |
| 20 | + Updated timetypes.RFC3339 `tfsdk:"updated"` |
| 21 | + Expiry timetypes.RFC3339 `tfsdk:"expiry"` |
| 22 | + Images types.List `tfsdk:"images"` |
| 23 | +} |
| 24 | + |
| 25 | +type ImageShareAttributesModel struct { |
| 26 | + ID types.String `tfsdk:"id"` |
| 27 | + Label types.String `tfsdk:"label"` |
| 28 | + Description types.String `tfsdk:"description"` |
| 29 | +} |
| 30 | + |
| 31 | +func (data *ResourceModel) FlattenImageShareGroup( |
| 32 | + imageShareGroup *linodego.ProducerImageShareGroup, |
| 33 | + preserveKnown bool, |
| 34 | +) { |
| 35 | + data.ID = helper.KeepOrUpdateInt64(data.ID, int64(imageShareGroup.ID), preserveKnown) |
| 36 | + data.UUID = helper.KeepOrUpdateString(data.UUID, imageShareGroup.UUID, preserveKnown) |
| 37 | + data.Label = helper.KeepOrUpdateString(data.Label, imageShareGroup.Label, preserveKnown) |
| 38 | + data.Description = helper.KeepOrUpdateString( |
| 39 | + data.Description, imageShareGroup.Description, preserveKnown, |
| 40 | + ) |
| 41 | + data.IsSuspended = helper.KeepOrUpdateBool(data.IsSuspended, imageShareGroup.IsSuspended, preserveKnown) |
| 42 | + data.ImagesCount = helper.KeepOrUpdateInt64(data.ImagesCount, int64(imageShareGroup.ImagesCount), preserveKnown) |
| 43 | + data.MembersCount = helper.KeepOrUpdateInt64(data.MembersCount, int64(imageShareGroup.MembersCount), preserveKnown) |
| 44 | + data.Created = helper.KeepOrUpdateValue( |
| 45 | + data.Created, timetypes.NewRFC3339TimePointerValue(imageShareGroup.Created), preserveKnown, |
| 46 | + ) |
| 47 | + data.Updated = helper.KeepOrUpdateValue( |
| 48 | + data.Updated, timetypes.NewRFC3339TimePointerValue(imageShareGroup.Updated), preserveKnown, |
| 49 | + ) |
| 50 | + data.Expiry = helper.KeepOrUpdateValue( |
| 51 | + data.Expiry, timetypes.NewRFC3339TimePointerValue(imageShareGroup.Expiry), preserveKnown, |
| 52 | + ) |
| 53 | + |
| 54 | + // Images must persist in state across CRUD operations but is not returned by the API. It will be maintained |
| 55 | + // manually as a part of Create, Update, and Read, so we only need to set it here if it is null so that it is |
| 56 | + // properly typed. |
| 57 | + if data.Images.IsNull() { |
| 58 | + data.Images = types.ListNull(imageShareGroupImage.Type()) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +type DataSourceModel struct { |
| 63 | + ID types.Int64 `tfsdk:"id"` |
| 64 | + UUID types.String `tfsdk:"uuid"` |
| 65 | + Label types.String `tfsdk:"label"` |
| 66 | + Description types.String `tfsdk:"description"` |
| 67 | + IsSuspended types.Bool `tfsdk:"is_suspended"` |
| 68 | + ImagesCount types.Int64 `tfsdk:"images_count"` |
| 69 | + MembersCount types.Int64 `tfsdk:"members_count"` |
| 70 | + Created timetypes.RFC3339 `tfsdk:"created"` |
| 71 | + Updated timetypes.RFC3339 `tfsdk:"updated"` |
| 72 | + Expiry timetypes.RFC3339 `tfsdk:"expiry"` |
| 73 | +} |
| 74 | + |
| 75 | +func (data *DataSourceModel) ParseImageShareGroup(isg *linodego.ProducerImageShareGroup, |
| 76 | +) diag.Diagnostics { |
| 77 | + data.ID = types.Int64Value(int64(isg.ID)) |
| 78 | + data.UUID = types.StringValue(isg.UUID) |
| 79 | + data.Label = types.StringValue(isg.Label) |
| 80 | + data.Description = types.StringValue(isg.Description) |
| 81 | + data.IsSuspended = types.BoolValue(isg.IsSuspended) |
| 82 | + data.ImagesCount = types.Int64Value(int64(isg.ImagesCount)) |
| 83 | + data.MembersCount = types.Int64Value(int64(isg.MembersCount)) |
| 84 | + data.Created = timetypes.NewRFC3339TimePointerValue(isg.Created) |
| 85 | + data.Updated = timetypes.NewRFC3339TimePointerValue(isg.Updated) |
| 86 | + data.Expiry = timetypes.NewRFC3339TimePointerValue(isg.Expiry) |
| 87 | + |
| 88 | + return nil |
| 89 | +} |
0 commit comments