Skip to content

Commit c157b16

Browse files
committed
Update inventory docs
1 parent 2ac0f8e commit c157b16

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

docs/data-sources/inventory.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ output "inventory_details" {
4545
<!-- schema generated by tfplugindocs -->
4646
## Schema
4747

48-
### Required
48+
### Optional
4949

5050
- `id` (Number) Inventory id
51+
- `name` (String) Name of the inventory
52+
- `organization_name` (String) The name for the organization to which the inventory belongs
5153

5254
### Read-Only
5355

5456
- `description` (String) Description of the inventory
55-
- `name` (String) Name of the inventory
57+
- `named_url` (String) The Named Url of the inventory
5658
- `organization` (Number) Identifier for the organization to which the inventory belongs
5759
- `url` (String) Url of the inventory
5860
- `variables` (String) Variables of the inventory. Will be either JSON or YAML string depending on how the variables were entered into AAP.

docs/resources/inventory.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,6 @@ output "inventory_xyz" {
111111
### Read-Only
112112

113113
- `id` (Number) Inventory id
114+
- `named_url` (String) Named URL of the inventory
115+
- `organization_name` (String) Name for the organization.
114116
- `url` (String) URL of the inventory

internal/provider/inventory_data_source.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1313
"github.com/hashicorp/terraform-plugin-framework/diag"
1414
tfpath "github.com/hashicorp/terraform-plugin-framework/path"
15-
"github.com/hashicorp/terraform-plugin-framework/provider"
1615
"github.com/hashicorp/terraform-plugin-framework/types"
1716
)
1817

@@ -38,6 +37,7 @@ var (
3837
_ datasource.DataSource = &InventoryDataSource{}
3938
_ datasource.DataSourceWithConfigure = &InventoryDataSource{}
4039
_ datasource.DataSourceWithConfigValidators = &InventoryDataSource{}
40+
_ datasource.DataSourceWithValidateConfig = &InventoryDataSource{}
4141
)
4242

4343
// NewInventoryDataSource is a helper function to simplify the provider implementation.
@@ -96,6 +96,7 @@ func (d *InventoryDataSource) Schema(_ context.Context, _ datasource.SchemaReque
9696

9797
// Read refreshes the Terraform state with the latest data.
9898
func (d *InventoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
99+
99100
var state InventoryDataSourceModel
100101
var diags diag.Diagnostics
101102

@@ -107,7 +108,6 @@ func (d *InventoryDataSource) Read(ctx context.Context, req datasource.ReadReque
107108

108109
URI := path.Join(d.client.getApiEndpoint(), "inventories")
109110
resourceURL, err := ReturnAAPNamedURL(state.Id, state.Name, state.OrganizationName, URI)
110-
// resourceURL, err := state.ResourceUrlFromParameters(d)
111111
if err != nil {
112112
resp.Diagnostics.AddError("Minimal Data Not Supplied", "Expected either [id] or [name + organization_name] pair")
113113
return
@@ -164,7 +164,7 @@ func (d *InventoryDataSource) ConfigValidators(_ context.Context) []datasource.C
164164
}
165165
}
166166

167-
func (d *InventoryDataSource) ValidateConfig(ctx context.Context, req provider.ValidateConfigRequest, resp *provider.ValidateConfigResponse) {
167+
func (d *InventoryDataSource) ValidateConfig(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) {
168168
var data InventoryDataSourceModel
169169

170170
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
@@ -181,23 +181,23 @@ func (d *InventoryDataSource) ValidateConfig(ctx context.Context, req provider.V
181181
return
182182
}
183183

184-
if IsValueNotProvided(data.Id) && IsValueNotProvided(data.Name) {
184+
if !IsValueProvided(data.Id) && !IsValueProvided(data.Name) {
185185
resp.Diagnostics.AddAttributeWarning(
186186
tfpath.Root("id"),
187187
"Missing Atribute Configuration",
188188
"Expected either [id] or [name + organization_name] pair",
189189
)
190190
}
191191

192-
if IsValueProvided(data.Name) && IsValueNotProvided(data.OrganizationName) {
192+
if IsValueProvided(data.Name) && !IsValueProvided(data.OrganizationName) {
193193
resp.Diagnostics.AddAttributeWarning(
194194
tfpath.Root("organization_name"),
195195
"Missing Attribute Configuration",
196196
"Expected organization_name to be configured with name.",
197197
)
198198
}
199199

200-
if IsValueNotProvided(data.Name) && IsValueProvided(data.OrganizationName) {
200+
if !IsValueProvided(data.Name) && IsValueProvided(data.OrganizationName) {
201201
resp.Diagnostics.AddAttributeWarning(
202202
tfpath.Root("name"),
203203
"Missing Attribute Configuration",

internal/provider/inventory_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (r *InventoryResourceModel) generateRequestBody() ([]byte, diag.Diagnostics
291291
organizationId = r.Organization.ValueInt64()
292292
}
293293

294-
if IsValueNotProvided(r.NamedUrl) {
294+
if !IsValueProvided(r.NamedUrl) {
295295
namedURL, err := ReturnAAPNamedURL(r.Id, r.Name, r.OrganizationName, "inventories")
296296
// Squashing error here. If we can't generate the named url just leave it blank
297297
if err == nil {

internal/provider/utils.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ import (
1919
func ReturnAAPNamedURL(id types.Int64, name types.String, orgName types.String, URI string) (string, error) {
2020
if IsValueProvided(id) {
2121
return path.Join(URI, id.String()), nil
22-
} else if IsValueProvided(name) && IsValueProvided(orgName) {
22+
}
23+
24+
if IsValueProvided(name) && IsValueProvided(orgName) {
2325
namedUrl := fmt.Sprintf("%s++%s", name.ValueString(), orgName.ValueString())
2426
return path.Join(URI, namedUrl), nil
25-
} else {
26-
return "", errors.New("invalid lookup parameters")
2727
}
28-
}
2928

30-
func IsValueNotProvided(value attr.Value) bool {
31-
return value.IsNull() || value.IsUnknown()
29+
return "", errors.New("invalid lookup parameters")
30+
3231
}
3332

3433
func IsValueProvided(value attr.Value) bool {

0 commit comments

Comments
 (0)