Skip to content

Commit

Permalink
Add external_id to resource_catalog_entry
Browse files Browse the repository at this point in the history
- This will allow users to set an external ID using this resource
  • Loading branch information
rorymalcolm committed Oct 23, 2024
1 parent 8177c4b commit a0fa2a2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
40 changes: 25 additions & 15 deletions docs/resources/catalog_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ If you're working with a large number of entries (>100) or want to be authoritat
## Example Usage

```terraform
locals {
service_tiers = [
{
name = "tier_1"
description = "Critical customer-facing services"
external_id = "service-tier-1"
},
{
name = "tier_2"
description = "Either customers or internal user processes are impacted if this service fails"
external_id = "service-tier-2"
},
{
name = "tier_3"
description = "Non-essential services"
external_id = "service-tier-3"
},
]
}
resource "incident_catalog_type" "service_tier" {
name = "Service Tier"
description = "Level of importance for each service"
Expand All @@ -35,27 +55,16 @@ resource "incident_catalog_type_attribute" "service_tier_description" {
}
resource "incident_catalog_entry" "service_tier" {
for_each = {
for name, tier in [
{
name = "tier_1"
description = "Critical customer-facing services"
},
{
name = "tier_2"
description = "Either customers or internal user processes are impacted if this service fails"
},
{
name = "tier_3"
description = "Non-essential services"
},
] : tier.name => tier
for_each = { for tier in local.service_tiers :
tier.name => tier
}
catalog_type_id = incident_catalog_type.service_tier.id
name = each.value.name
external_id = each.value.external_id
attribute_values = [
{
attribute = incident_catalog_type_attribute.service_tier_description.id,
Expand All @@ -77,6 +86,7 @@ resource "incident_catalog_entry" "service_tier" {
### Optional

- `aliases` (List of String) Optional aliases that can be used to reference this entry
- `external_id` (String) An optional alternative ID for this entry, which is ensured to be unique for the type
- `rank` (Number) When catalog type is ranked, this is used to help order things

### Read-Only
Expand Down
39 changes: 24 additions & 15 deletions examples/resources/incident_catalog_entry/resource.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
locals {
service_tiers = [
{
name = "tier_1"
description = "Critical customer-facing services"
external_id = "service-tier-1"
},
{
name = "tier_2"
description = "Either customers or internal user processes are impacted if this service fails"
external_id = "service-tier-2"
},
{
name = "tier_3"
description = "Non-essential services"
external_id = "service-tier-3"
},
]
}

resource "incident_catalog_type" "service_tier" {
name = "Service Tier"
description = "Level of importance for each service"
Expand All @@ -11,27 +31,16 @@ resource "incident_catalog_type_attribute" "service_tier_description" {
}

resource "incident_catalog_entry" "service_tier" {
for_each = {
for name, tier in [
{
name = "tier_1"
description = "Critical customer-facing services"
},
{
name = "tier_2"
description = "Either customers or internal user processes are impacted if this service fails"
},
{
name = "tier_3"
description = "Non-essential services"
},
] : tier.name => tier
for_each = { for tier in local.service_tiers :
tier.name => tier
}

catalog_type_id = incident_catalog_type.service_tier.id

name = each.value.name

external_id = each.value.external_id

attribute_values = [
{
attribute = incident_catalog_type_attribute.service_tier_description.id,
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/incident_catalog_entry_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type IncidentCatalogEntryResourceModel struct {
ID types.String `tfsdk:"id"`
CatalogTypeID types.String `tfsdk:"catalog_type_id"`
Name types.String `tfsdk:"name"`
ExternalID types.String `tfsdk:"external_id"`
Aliases types.List `tfsdk:"aliases"`
Rank types.Int64 `tfsdk:"rank"`
AttributeValues []CatalogEntryAttributeValue `tfsdk:"attribute_values"`
Expand Down Expand Up @@ -111,6 +112,10 @@ If you're working with a large number of entries (>100) or want to be authoritat
MarkdownDescription: apischema.Docstring("CatalogEntryV2", "name"),
Required: true,
},
"external_id": schema.StringAttribute{
MarkdownDescription: apischema.Docstring("CatalogEntryV2", "external_id"),
Optional: true,
},
"aliases": schema.ListAttribute{
ElementType: types.StringType,
PlanModifiers: []planmodifier.List{
Expand Down Expand Up @@ -189,6 +194,7 @@ func (r *IncidentCatalogEntryResource) Create(ctx context.Context, req resource.
result, err := r.client.CatalogV2CreateEntryWithResponse(ctx, client.CreateEntryRequestBody{
CatalogTypeId: data.CatalogTypeID.ValueString(),
Name: data.Name.ValueString(),
ExternalId: data.ExternalID.ValueStringPointer(),
Rank: rank,
Aliases: &aliases,
AttributeValues: data.buildAttributeValues(),
Expand Down Expand Up @@ -256,6 +262,7 @@ func (r *IncidentCatalogEntryResource) Update(ctx context.Context, req resource.
result, err := r.client.CatalogV2UpdateEntryWithResponse(ctx, data.ID.ValueString(), client.UpdateEntryRequestBody{
Name: data.Name.ValueString(),
Rank: rank,
ExternalId: data.ExternalID.ValueStringPointer(),
Aliases: &aliases,
AttributeValues: data.buildAttributeValues(),
})
Expand Down Expand Up @@ -334,6 +341,7 @@ func (r *IncidentCatalogEntryResource) buildModel(entry client.CatalogEntryV2) *
ID: types.StringValue(entry.Id),
CatalogTypeID: types.StringValue(entry.CatalogTypeId),
Name: types.StringValue(entry.Name),
ExternalID: types.StringPointerValue(entry.ExternalId),
Aliases: types.ListValueMust(types.StringType, aliases),
Rank: types.Int64Value(int64(entry.Rank)),
AttributeValues: values,
Expand Down

0 comments on commit a0fa2a2

Please sign in to comment.