Skip to content

Commit

Permalink
change resource name tco_policy to tco_policy_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
OrNovo committed Aug 9, 2023
1 parent 4f02fa8 commit a77de0e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 51 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ INTERNAL CHANGES:

## Release 1.7.0
Breaking Changes:
#### resource/coralogix_tco_policy
**Please note** - this version contains a [State Upgrader](https://developer.hashicorp.com/terraform/plugin/framework/migrating/resources/state-upgrade#framework). It will upgrade the state to the new schema. Please make sure to back up your state before upgrading.
#### resource/coralogix_tco_policy was changed to coralogix_tco_policy_logs and contains the next changes:
* `subsystem_name` was changed to `subsystems` and have different structure e.g. -
`subsystem_name {
is = true
Expand All @@ -263,10 +262,12 @@ Breaking Changes:
starts_with = true
rule = "prod"
}` => `applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}`


**Please note** - this version contains a [State Upgrader](https://developer.hashicorp.com/terraform/plugin/framework/migrating/resources/state-upgrade#framework). It will upgrade the state to the new schema. Please make sure to back up your state before upgrading.
(for upgrading the schemas the resource names have to be change manually to coralogix_tco_policy_logs before upgrading)
DEVELOPERS:
#### resource/coralogix_tco_policy
* using grpc endpoint instead of the REST endpoint.
Expand Down
2 changes: 1 addition & 1 deletion coralogix/data_source_coralogix_tco_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TCOPolicyDataSource struct {
}

func (d *TCOPolicyDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_tco_policy"
resp.TypeName = req.ProviderTypeName + "_tco_policy_logs"
}

func (d *TCOPolicyDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
Expand Down
4 changes: 2 additions & 2 deletions coralogix/data_source_coralogix_tco_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestAccCoralogixDataSourceTCOPolicy_basic(t *testing.T) {
}

func testAccCoralogixResourceTCOPolicy_read() string {
return `data "coralogix_tco_policy" "test_1" {
id = coralogix_tco_policy.test_1.id
return `data "coralogix_tco_policy_logs" "test_1" {
id = coralogix_tco_policy_logs.test_1.id
}
`
}
5 changes: 2 additions & 3 deletions coralogix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ func OldProvider() *oldSchema.Provider {
"coralogix_dashboard": dataSourceCoralogixDashboard(),
"coralogix_hosted_dashboard": dataSourceCoralogixHostedDashboard(),
"coralogix_recording_rules_groups_set": dataSourceCoralogixRecordingRulesGroupsSet(),
//"coralogix_tco_policy": dataSourceCoralogixTCOPolicy(),
"coralogix_tco_policy_override": dataSourceCoralogixTCOPolicyOverride(),
"coralogix_webhook": dataSourceCoralogixWebhook(),
"coralogix_tco_policy_override": dataSourceCoralogixTCOPolicyOverride(),
"coralogix_webhook": dataSourceCoralogixWebhook(),
},

ResourcesMap: map[string]*oldSchema.Resource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ var (
tcoPoliciesValidPriorities = GetKeys(tcoPoliciesPrioritySchemaToProto)
tcoPoliciesRuleTypeSchemaToProto = map[string]tcopolicies.RuleTypeId{
"is": tcopolicies.RuleTypeId_RULE_TYPE_ID_IS,
"is not": tcopolicies.RuleTypeId_RULE_TYPE_ID_IS_NOT,
"starts with": tcopolicies.RuleTypeId_RULE_TYPE_ID_START_WITH,
"is_not": tcopolicies.RuleTypeId_RULE_TYPE_ID_IS_NOT,
"starts_with": tcopolicies.RuleTypeId_RULE_TYPE_ID_START_WITH,
"includes": tcopolicies.RuleTypeId_RULE_TYPE_ID_INCLUDES,
}
tcoPoliciesRuleTypeProtoToSchema = ReverseMap(tcoPoliciesRuleTypeSchemaToProto)
Expand Down Expand Up @@ -88,7 +88,7 @@ type TCORuleModel struct {
}

func (r *TCOPolicyResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_tco_policy"
resp.TypeName = req.ProviderTypeName + "_tco_policy_logs"
}

func (r *TCOPolicyResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand Down Expand Up @@ -185,6 +185,7 @@ func (r *TCOPolicyResource) Schema(_ context.Context, _ resource.SchemaRequest,
Validators: []validator.String{
stringvalidator.OneOf(tcoPoliciesValidRuleTypes...),
},
MarkdownDescription: fmt.Sprintf("The rule type. Can be one of %q.", tcoPoliciesValidRuleTypes),
},
},
MarkdownDescription: "The applications to apply the policy on. Applies the policy on all the applications by default.",
Expand Down Expand Up @@ -233,7 +234,7 @@ func validateTCORuleModelModel(rule *TCORuleModel, root string, resp *resource.V
if rule != nil {
ruleType := rule.RuleType.ValueString()
nameLength := len(rule.Names.Elements())
if (ruleType == "starts with" || ruleType == "includes") && nameLength > 1 {
if (ruleType == "starts_with" || ruleType == "includes") && nameLength > 1 {
resp.Diagnostics.AddAttributeWarning(
path.Root(root),
"Conflicting Attributes Values Configuration",
Expand Down Expand Up @@ -308,11 +309,11 @@ func upgradeTCOPolicyRuleV0ToV1(ctx context.Context, tCOPolicyRule types.List) *
if tCORuleModelObjectV0.Is.ValueBool() {
tCORuleModelObjectV1.RuleType = types.StringValue("is")
} else if tCORuleModelObjectV0.IsNot.ValueBool() {
tCORuleModelObjectV1.RuleType = types.StringValue("is not")
tCORuleModelObjectV1.RuleType = types.StringValue("is_not")
} else if tCORuleModelObjectV0.Include.ValueBool() {
tCORuleModelObjectV1.RuleType = types.StringValue("includes")
} else if tCORuleModelObjectV0.StartsWith.ValueBool() {
tCORuleModelObjectV1.RuleType = types.StringValue("starts with")
tCORuleModelObjectV1.RuleType = types.StringValue("starts_with")
}

if rule := tCORuleModelObjectV0.Rule.ValueString(); rule != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
tcopolicies "terraform-provider-coralogix/coralogix/clientset/grpc/tco-policies"
)

var tcoPolicyResourceName1 = "coralogix_tco_policy.test_1"
var tcoPolicyResourceName2 = "coralogix_tco_policy.test_2"
var tcoPolicyResourceName3 = "coralogix_tco_policy.test_3"
var tcoPolicyResourceName1 = "coralogix_tco_policy_logs.test_1"
var tcoPolicyResourceName2 = "coralogix_tco_policy_logs.test_2"
var tcoPolicyResourceName3 = "coralogix_tco_policy_logs.test_3"

func TestAccCoralogixResourceTCOPolicyCreate(t *testing.T) {
resource.Test(t, resource.TestCase{
Expand All @@ -33,7 +33,7 @@ func TestAccCoralogixResourceTCOPolicyCreate(t *testing.T) {
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName1, "severities.*", "debug"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName1, "severities.*", "verbose"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName1, "severities.*", "info"),
resource.TestCheckResourceAttr(tcoPolicyResourceName1, "applications.rule_type", "starts with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName1, "applications.rule_type", "starts_with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName1, "applications.names.0", "prod"),
resource.TestCheckResourceAttr(tcoPolicyResourceName1, "subsystems.rule_type", "is"),
resource.TestCheckResourceAttr(tcoPolicyResourceName1, "subsystems.names.#", "2"),
Expand All @@ -48,7 +48,7 @@ func TestAccCoralogixResourceTCOPolicyCreate(t *testing.T) {
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName2, "severities.*", "error"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName2, "severities.*", "warning"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName2, "severities.*", "critical"),
resource.TestCheckResourceAttr(tcoPolicyResourceName2, "applications.rule_type", "starts with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName2, "applications.rule_type", "starts_with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName2, "applications.names.0", "prod"),
resource.TestCheckResourceAttr(tcoPolicyResourceName2, "subsystems.rule_type", "is"),
resource.TestCheckResourceAttr(tcoPolicyResourceName2, "subsystems.names.#", "2"),
Expand All @@ -62,7 +62,7 @@ func TestAccCoralogixResourceTCOPolicyCreate(t *testing.T) {
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName3, "severities.*", "debug"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName3, "severities.*", "verbose"),
resource.TestCheckTypeSetElemAttr(tcoPolicyResourceName3, "severities.*", "info"),
resource.TestCheckResourceAttr(tcoPolicyResourceName3, "applications.rule_type", "starts with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName3, "applications.rule_type", "starts_with"),
resource.TestCheckResourceAttr(tcoPolicyResourceName3, "applications.names.0", "prod"),
resource.TestCheckResourceAttr(tcoPolicyResourceName3, "subsystems.rule_type", "is"),
resource.TestCheckResourceAttr(tcoPolicyResourceName3, "subsystems.names.#", "2"),
Expand All @@ -78,7 +78,7 @@ func testAccTCOPolicyCheckDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*clientset.ClientSet).TCOPolicies()
ctx := context.TODO()
for _, rs := range s.RootModule().Resources {
if rs.Type != "coralogix_tco_policy" {
if rs.Type != "coralogix_tco_policy_logs" {
continue
}

Expand All @@ -97,13 +97,13 @@ func testAccTCOPolicyCheckDestroy(s *terraform.State) error {

func testAccCoralogixResourceTCOPolicy() string {
return fmt.Sprintf(
`resource "coralogix_tco_policy" test_1 {
`resource "coralogix_tco_policy_logs" test_1 {
name = "Example tco_policy from terraform 1"
priority = "low"
order = 1
severities = ["debug", "verbose", "info"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand All @@ -113,13 +113,13 @@ func testAccCoralogixResourceTCOPolicy() string {
archive_retention_id = "e1c980d0-c910-4c54-8326-67f3cf95645a"
}
resource "coralogix_tco_policy" test_2 {
resource "coralogix_tco_policy_logs" test_2 {
name = "Example tco_policy from terraform 2"
priority = "medium"
order = coralogix_tco_policy.test_1.order + 1
order = coralogix_tco_policy_logs.test_1.order + 1
severities = ["error", "warning", "critical"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand All @@ -128,13 +128,13 @@ func testAccCoralogixResourceTCOPolicy() string {
}
}
resource "coralogix_tco_policy" test_3 {
resource "coralogix_tco_policy_logs" test_3 {
name = "Example tco_policy from terraform 3"
order = coralogix_tco_policy.test_2.order + 1
order = coralogix_tco_policy_logs.test_2.order + 1
priority = "high"
severities = ["debug", "verbose", "info"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coralogix_tco_policy Data Source - terraform-provider-coralogix"
page_title: "coralogix_tco_policy_logs Data Source - terraform-provider-coralogix"
subcategory: ""
description: "Coralogix TCO-Policy. For more information - https://coralogix.com/docs/tco-optimizer-api ."
description: |-
Coralogix TCO-Policy. For more information - https://coralogix.com/docs/tco-optimizer-api .
---

# coralogix_tco_policy (Data Source)
# coralogix_tco_policy_logs (Data Source)

Coralogix TCO-Policy. For more information - https://coralogix.com/docs/tco-optimizer-api .

## Example Usage

```hcl
data "coralogix_tco_policy" "imported_coralogix_tco_policy" {
data "coralogix_tco_policy_logs" "imported_coralogix_tco_policy" {
id = coralogix_tco_policy.tco_policy_example.id
}
```
Expand All @@ -32,7 +33,7 @@ data "coralogix_tco_policy" "imported_coralogix_tco_policy" {
- `enabled` (Boolean) Determines weather the policy will be enabled. True by default.
- `name` (String) tco-policy name.
- `order` (Number) Determines the policy's order between the other policies.
- `priority` (String) The policy priority. Can be one of ["medium" "block" "high" "low"].
- `priority` (String) The policy priority. Can be one of ["block" "high" "low" "medium"].
- `severities` (Set of String) The severities to apply the policy on. Can be few of ["debug" "verbose" "info" "warning" "error" "critical"].
- `subsystems` (Attributes) The subsystems to apply the policy on. Applies the policy on all the subsystems by default. (see [below for nested schema](#nestedatt--subsystems))

Expand All @@ -42,7 +43,7 @@ data "coralogix_tco_policy" "imported_coralogix_tco_policy" {
Read-Only:

- `names` (Set of String)
- `rule_type` (String)
- `rule_type` (String) The rule type. Can be one of ["is" "is_not" "starts_with" "includes"].


<a id="nestedatt--subsystems"></a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coralogix_tco_policy Resource - terraform-provider-coralogix"
page_title: "coralogix_tco_policy_logs Resource - terraform-provider-coralogix"
subcategory: ""
description: "Coralogix TCO-Policy. For more information - https://coralogix.com/docs/tco-optimizer-api ."
---

# coralogix_tco_policy (Resource)
# coralogix_tco_policy_logs (Resource)

Coralogix TCO-Policy. For more information - https://coralogix.com/docs/tco-optimizer-api .

**Please note** - [Policies order issue](https://github.com/coralogix/terraform-provider-coralogix/issues/114)
## Example Usage

```hcl
resource "coralogix_tco_policy" "tco_policy_1" {
resource "coralogix_tco_policy_logs" "tco_policy_1" {
name = "Example tco_policy from terraform 1"
priority = "low"
order = 1
Expand All @@ -29,7 +29,7 @@ resource "coralogix_tco_policy" "tco_policy_1" {
archive_retention_id = "e1c980d0-c910-4c54-8326-67f3cf95645a"
}
resource "coralogix_tco_policy" "tco_policy_2" {
resource "coralogix_tco_policy_logs" "tco_policy_2" {
name = "Example tco_policy from terraform 2"
priority = "medium"
order = 2
Expand All @@ -53,7 +53,7 @@ resource "coralogix_tco_policy" "tco_policy_2" {

- `name` (String) tco-policy name.
- `order` (Number) Determines the policy's order between the other policies.
- `priority` (String) The policy priority. Can be one of ["medium" "block" "high" "low"].
- `priority` (String) The policy priority. Can be one of ["block" "high" "low" "medium"].

### Optional

Expand All @@ -77,7 +77,7 @@ Required:

Optional:

- `rule_type` (String)
- `rule_type` (String) The rule type. Can be one of ["is" "is_not" "starts_with" "includes"].


<a id="nestedatt--subsystems"></a>
Expand Down
16 changes: 8 additions & 8 deletions examples/tco_policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ provider "coralogix" {
#env = "<add the environment you want to work at or add env variable CORALOGIX_ENV>"
}

resource "coralogix_tco_policy" "tco_policy_1" {
resource "coralogix_tco_policy_logs" "tco_policy_1" {
name = "Example tco_policy from terraform 1"
priority = "low"
order = 1
severities = ["debug", "verbose", "info"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand All @@ -28,14 +28,14 @@ resource "coralogix_tco_policy" "tco_policy_1" {
archive_retention_id = "e1c980d0-c910-4c54-8326-67f3cf95645a"
}

resource "coralogix_tco_policy" "tco_policy_2" {
resource "coralogix_tco_policy_logs" "tco_policy_2" {
name = "Example tco_policy from terraform 2"
priority = "medium"
order = 2

severities = ["error", "warning", "critical"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand All @@ -44,14 +44,14 @@ resource "coralogix_tco_policy" "tco_policy_2" {
}
}

resource "coralogix_tco_policy" "tco_policy_3" {
resource "coralogix_tco_policy_logs" "tco_policy_3" {
name = "Example tco_policy from terraform 3"
priority = "high"
order = 3

severities = ["error", "warning", "critical"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand All @@ -60,14 +60,14 @@ resource "coralogix_tco_policy" "tco_policy_3" {
}
}

resource "coralogix_tco_policy" "tco_policy_4" {
resource "coralogix_tco_policy_logs" "tco_policy_4" {
name = "Example tco_policy from terraform 4"
priority = "high"
order = 4

severities = ["error", "warning", "critical"]
applications = {
rule_type = "starts with"
rule_type = "starts_with"
names = ["prod"]
}
subsystems = {
Expand Down

0 comments on commit a77de0e

Please sign in to comment.