Skip to content

Commit 42cc76e

Browse files
authored
Force recreation of catalog entity on type change (#75)
https://cortex1.atlassian.net/browse/CET-21595 Update the `cortex_catalog_entity` resource to ensure that changing the entity type triggers a resource replacement. Include tests to verify this behavior. Bump version to 0.4.7 and backfill changelog with previous updates.
1 parent 9876410 commit 42cc76e

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@ Changelog for the Cortex terraform provider.
22

33
## Unreleased
44

5+
## 0.4.7
6+
* Updates to `cortex_catalog_entity` resource to force resource recreation when the type is changed.
7+
8+
## 0.4.6
9+
* Version bump in Makefile
10+
11+
## 0.4.5
12+
* Fix acceptance tests
13+
* Enhance team data source to return team members and slack channels
14+
* Fix readme provider source and version pinning
15+
* Bump github.com/life4/genesis from 1.8.1 to 1.10.2
16+
17+
## 0.4.4
18+
* Fix for broken integration test
19+
* Add support for an Open API specification to be associated with an Entity
20+
21+
## 0.4.3
22+
* Remove category usage in tests, add deprecation for scorecard category field
23+
* Make `draft` optional for scorecards
24+
* Update test requirements for PRs and `main` branch
25+
* Fix CI Suite, support CircleCI stanza for catalog entities
26+
* Move CI suite to Terraform 1.10
27+
528
## 0.4.2
629
* Fixes `cortex_scorecard` resource so that `rules` are a set. Order doesn't matter.
730

@@ -10,7 +33,7 @@ Changelog for the Cortex terraform provider.
1033

1134
## 0.4.0
1235
* Deprecate `x-cortex-parents` and use `x-cortex-parents` instead
13-
- Bump Go version 1.20 -> 1.22
36+
* Bump Go version 1.20 -> 1.22
1437

1538
## 0.3.1
1639
* Fix serialization for `git` / `sonarqube` / `codecov`

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ HOSTNAME=github.com
22
NAMESPACE=cortexapps
33
NAME=cortex
44
BINARY=terraform-provider-${NAME}
5-
VERSION=0.4.6-dev
5+
VERSION=0.4.7-dev
66

77
GOOS?=$(shell go env | grep GOOS | cut -d '=' -f2 | tr -d "'")
88
GOARCH?=$(shell go env | grep GOARCH | cut -d '=' -f2 | tr -d "'")

docs/resources/catalog_entity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Catalog Entity
5555
- `snyk` (Attributes) Snyk configuration for the entity. (see [below for nested schema](#nestedatt--snyk))
5656
- `static_analysis` (Attributes) Static analysis configuration for the entity. (see [below for nested schema](#nestedatt--static_analysis))
5757
- `team` (Attributes) Team configuration for the entity. Only used for entities of type `TEAM`. (see [below for nested schema](#nestedatt--team))
58-
- `type` (String) Set when the entity is a Resource or Team. This must match a tag of a valid Resource Definition or be "team" or "domain".
58+
- `type` (String) Set when the entity is a Resource or Team. This must match a tag of a valid Resource Definition or be "team" or "domain". **Note:** Changing this attribute will force replacement of the resource.
5959
- `wiz` (Attributes) Wiz configuration for the entity. (see [below for nested schema](#nestedatt--wiz))
6060

6161
### Read-Only

internal/provider/catalog_entity_resource.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ func (r *CatalogEntityResource) Schema(ctx context.Context, req resource.SchemaR
7373
},
7474
},
7575
"type": schema.StringAttribute{
76-
MarkdownDescription: "Set when the entity is a Resource or Team. This must match a tag of a valid Resource Definition or be \"team\" or \"domain\".",
76+
MarkdownDescription: "Set when the entity is a Resource or Team. This must match a tag of a valid Resource Definition or be \"team\" or \"domain\". **Note:** Changing this attribute will force replacement of the resource.",
7777
Optional: true,
78+
PlanModifiers: []planmodifier.String{
79+
stringplanmodifier.RequiresReplace(),
80+
},
7881
},
7982
"definition": schema.StringAttribute{
8083
MarkdownDescription: "Set when the entity is a Resource. These are the properties defined by the Resource Definition, in JSON format in a string (use the `jsonencode` function to convert a JSON object to a string).",

internal/provider/catalog_entity_resource_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,47 @@ resource "cortex_catalog_entity" "test-unmanaged-metadata" {
679679
})
680680
}`, tag, name, description)
681681
}
682+
683+
func TestAccCatalogEntityResourceTypeRequiresReplace(t *testing.T) {
684+
tag := "test-type-requires-replace"
685+
resourceName := "cortex_catalog_entity.test-type-requires-replace"
686+
name := "Type Requires Replace Test Entity"
687+
description := "Entity to test type attribute RequiresReplace behavior"
688+
resource.Test(t, resource.TestCase{
689+
PreCheck: func() { testAccPreCheck(t) },
690+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
691+
Steps: []resource.TestStep{
692+
// Create with type "team"
693+
{
694+
Config: testAccCatalogEntityResourceTypeRequiresReplace(tag, name, description, "team"),
695+
Check: resource.ComposeAggregateTestCheckFunc(
696+
resource.TestCheckResourceAttr(resourceName, "tag", tag),
697+
resource.TestCheckResourceAttr(resourceName, "name", name),
698+
resource.TestCheckResourceAttr(resourceName, "description", description),
699+
resource.TestCheckResourceAttr(resourceName, "type", "team"),
700+
),
701+
},
702+
// Update type to "domain" - should trigger replace
703+
{
704+
Config: testAccCatalogEntityResourceTypeRequiresReplace(tag, name, description, "domain"),
705+
Check: resource.ComposeAggregateTestCheckFunc(
706+
resource.TestCheckResourceAttr(resourceName, "tag", tag),
707+
resource.TestCheckResourceAttr(resourceName, "name", name),
708+
resource.TestCheckResourceAttr(resourceName, "description", description),
709+
resource.TestCheckResourceAttr(resourceName, "type", "domain"),
710+
),
711+
},
712+
// Delete testing automatically occurs in TestCase
713+
},
714+
})
715+
}
716+
717+
func testAccCatalogEntityResourceTypeRequiresReplace(tag string, name string, description string, entityType string) string {
718+
return fmt.Sprintf(`
719+
resource "cortex_catalog_entity" "test-type-requires-replace" {
720+
tag = %[1]q
721+
name = %[2]q
722+
description = %[3]q
723+
type = %[4]q
724+
}`, tag, name, description, entityType)
725+
}

0 commit comments

Comments
 (0)