Skip to content

Commit

Permalink
patch - remove org_key and upgrade api_key, custom_role, group and us…
Browse files Browse the repository at this point in the history
…er docs (#223)

* patch - remove org_key and upgrade api_key, custom_role, group and user docs
  • Loading branch information
OrNovo committed Apr 16, 2024
1 parent ade9ea8 commit 6813c99
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 61 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,8 @@ Bug fixing:
## Release 1.13.3
New Features:
#### resource/coralogix_webhook
* adding `attachments` to `slack` webhook type [attachments](docs/resources/webhook.md#nested-schema-for-slackattachments). fixing [issue](https://github.com/coralogix/terraform-provider-coralogix/issues/219).
* adding `attachments` to `slack` webhook type [attachments](docs/resources/webhook.md#nested-schema-for-slackattachments). fixing [issue](https://github.com/coralogix/terraform-provider-coralogix/issues/219).

## Release 1.13.4
Breaking Changes:
* `org_key` and `CORALOGIX_ORG_KEY` were removed from the provider configuration. use `api_key` and `CORALOGIX_API_KEY` instead.
7 changes: 3 additions & 4 deletions coralogix/clientset/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ func (c *ClientSet) Users() *UsersClient {
return c.users
}

func NewClientSet(targetUrl, apiKey, orgKey string) *ClientSet {
func NewClientSet(targetUrl, apiKey string) *ClientSet {
apikeyCPC := NewCallPropertiesCreator(targetUrl, apiKey)
teamsCPC := NewCallPropertiesCreator(targetUrl, orgKey)

return &ClientSet{
ruleGroups: NewRuleGroupsClient(apikeyCPC),
Expand All @@ -139,10 +138,10 @@ func NewClientSet(targetUrl, apiKey, orgKey string) *ClientSet {
archiveMetrics: NewArchiveMetricsClient(apikeyCPC),
archiveLogs: NewArchiveLogsClient(apikeyCPC),
alertsSchedulers: NewAlertsSchedulersClient(apikeyCPC),
teams: NewTeamsClient(teamsCPC),
teams: NewTeamsClient(apikeyCPC),
slos: NewSLOsClient(apikeyCPC),
dahboardsFolders: NewDashboardsFoldersClient(apikeyCPC),
apiKeys: NewApiKeysClient(teamsCPC),
apiKeys: NewApiKeysClient(apikeyCPC),
groups: NewGroupsClient(apikeyCPC),
users: NewUsersClient(apikeyCPC),
customRole: NewRolesClient(apikeyCPC),
Expand Down
40 changes: 5 additions & 35 deletions coralogix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ func OldProvider() *oldSchema.Provider {
//ValidateFunc: validation.IsUUID,
Description: "A key for using coralogix APIs (Auto Generated), appropriate for the defined environment. environment variable 'CORALOGIX_API_KEY' can be defined instead.",
},
"org_key": {
Type: oldSchema.TypeString,
Optional: true,
Sensitive: true,
Description: "A key for using coralogix APIs in the organisation level, appropriate for the defined environment. environment variable 'CORALOGIX_ORG_KEY' can be defined instead.",
},
},

DataSourcesMap: map[string]*oldSchema.Resource{
Expand Down Expand Up @@ -116,16 +110,11 @@ func OldProvider() *oldSchema.Provider {
apiKey = d.Get("api_key").(string)
}

orgKey := os.Getenv("CORALOGIX_ORG_KEY")
if orgKey == "" {
orgKey = d.Get("org_key").(string)
}

if apiKey == "" && orgKey == "" {
return nil, diag.Errorf("At least one of the fields 'api_key' or 'org_key', or one of the environment variables 'CORALOGIX_API_KEY' or 'CORALOGIX_ORG_KEY' have to be define")
if apiKey == "" {
return nil, diag.Errorf("At least one of the field 'api_key' or environment variable 'CORALOGIX_API_KEY' should be define")
}

return clientset.NewClientSet(targetUrl, apiKey, orgKey), nil
return clientset.NewClientSet(targetUrl, apiKey), nil
},
}
}
Expand All @@ -134,7 +123,6 @@ type coralogixProviderModel struct {
Env types.String `tfsdk:"env"`
Domain types.String `tfsdk:"domain"`
ApiKey types.String `tfsdk:"api_key"`
OrgKey types.String `tfsdk:"org_key"`
}

var (
Expand Down Expand Up @@ -174,11 +162,6 @@ func (p *coralogixProvider) Schema(_ context.Context, _ provider.SchemaRequest,
Sensitive: true,
Description: "A key for using coralogix APIs (Auto Generated), appropriate for the defined environment. environment variable 'CORALOGIX_API_KEY' can be defined instead.",
},
"org_key": schema.StringAttribute{
Optional: true,
Sensitive: true,
Description: "A key for using coralogix APIs in the organisation level, appropriate for the defined environment. environment variable 'CORALOGIX_ORG_KEY' can be defined instead.",
},
},
}
}
Expand Down Expand Up @@ -221,15 +204,6 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
)
}

if config.OrgKey.IsUnknown() {
resp.Diagnostics.AddAttributeError(
path.Root("org_key"),
"Unknown Coralogix API Org-Key",
"The provider cannot create the Coralogix API client as there is an unknown configuration value for the Coralogix Org-Key. "+
"Either target apply the source of the value first, set the value statically in the configuration, or use the CORALOGIX_ORG_KEY environment variable.",
)
}

if resp.Diagnostics.HasError() {
return
}
Expand All @@ -240,7 +214,6 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
domain := os.Getenv("CORALOGIX_DOMAIN")
env := os.Getenv("CORALOGIX_ENV")
apiKey := os.Getenv("CORALOGIX_API_KEY")
orgKey := os.Getenv("CORALOGIX_ORG_KEY")

if !config.Domain.IsNull() {
domain = config.Domain.ValueString()
Expand All @@ -254,9 +227,6 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
apiKey = config.ApiKey.ValueString()
}

if !config.OrgKey.IsNull() {
orgKey = config.OrgKey.ValueString()
}
// If any of the expected configurations are missing, return
// errors with provider-specific guidance.

Expand Down Expand Up @@ -288,7 +258,7 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
resp.Diagnostics.AddAttributeError(path.Root("env"), "Invalid Coralogix env", fmt.Sprintf("The Coralogix env must be one of %q", validEnvs))
}

if apiKey == "" && orgKey == "" {
if apiKey == "" {
resp.Diagnostics.AddAttributeError(
path.Root("api_key"),
"Missing Coralogix API API-Key",
Expand All @@ -309,7 +279,7 @@ func (p *coralogixProvider) Configure(ctx context.Context, req provider.Configur
targetUrl = fmt.Sprintf("ng-api-grpc.%s:443", domain)
}

clientSet := clientset.NewClientSet(targetUrl, apiKey, orgKey)
clientSet := clientset.NewClientSet(targetUrl, apiKey)
resp.DataSourceData = clientSet
resp.ResourceData = clientSet
}
Expand Down
4 changes: 0 additions & 4 deletions coralogix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ func testAccPreCheck(t *testing.T) {
if os.Getenv("CORALOGIX_ORG_KEY") == "" {
t.Fatalf("CORALOGIX_ORG_KEY must be set for acceptance tests")
}
//diags := testAccProvider.Configure(ctx, terraform.NewResourceConfigRaw(nil))
//if diags.HasError() {
// t.Fatal(diags[0].Summary)
//}
}
2 changes: 1 addition & 1 deletion docs/data-sources/api_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ Coralogix Api keys.

Read-Only:

- `team_id` (Number)
- `team_id` (String)
- `user_id` (String)
5 changes: 2 additions & 3 deletions docs/data-sources/custom_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "coralogix_custom_role Data Source - terraform-provider-coralogix"
subcategory: ""
description: |-
Coralogix Api keys.
Coralogix Custom roles.
---

# coralogix_custom_role (Data Source)

Coralogix Api keys.
Coralogix Custom roles.



Expand All @@ -25,4 +25,3 @@ Coralogix Api keys.
- `name` (String) Custom Role name.
- `parent_role` (String) Parent role name
- `permissions` (Set of String) Custom role permissions
- `team_id` (Number) Custom Role teamId.
8 changes: 7 additions & 1 deletion docs/resources/api_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ resource "coralogix_api_key" "example" {

Optional:

- `team_id` (Number)
- `team_id` (String)
- `user_id` (String)

### Import

```sh
terraform import coralogix_api_key.example <api_key-id>
```
34 changes: 32 additions & 2 deletions docs/resources/custom_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
page_title: "coralogix_custom_role Resource - terraform-provider-coralogix"
subcategory: ""
description: |-
Coralogix Api keys.
Coralogix Custom roles.
---

# coralogix_custom_role (Resource)

Coralogix Api keys.
Coralogix Custom roles.

## Example Usage

```hcl
resource "coralogix_custom_role" "example" {
name = "Example custom role"
description = "This role is created with terraform!"
parent_role = "Standard User"
permissions = ["spans.events2metrics:UpdateConfig"]
}
resource "coralogix_group" "example" {
display_name = "example"
role = coralogix_custom_role.example.name
}
```


<!-- schema generated by tfplugindocs -->
Expand All @@ -26,3 +41,18 @@ Coralogix Api keys.
### Read-Only

- `id` (String) Custom Role ID.

### Import

```sh
terraform import coralogix_custom_role.example <custom-role-id>
```

to get the custom role id you can use the following command:
```sh
grpcurl -H "Authorization: Bearer <api-key>" -d @ ng-api-grpc.<region-domain>:443 com.coralogixapis.aaa.rbac.v2.RoleManagementService/ListCustomRoles <<EOF
{
}
EOF
```
[region-domain table](../index.md#region-domain-table)
33 changes: 29 additions & 4 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ Coralogix group.
## Example Usage

```hcl
resource "coralogix_group" "example" {
display_name = "example"
role = "Read Only"
members = [coralogix_user.example.id]
resource "coralogix_custom_role" "example" {
name = "Example custom role"
description = "This role is created with terraform!"
parent_role = "Standard User"
permissions = ["spans.events2metrics:UpdateConfig"]
}
resource "coralogix_user" "example" {
user_name = "[email protected]"
name = {
given_name = "example"
family_name = "example"
}
}
resource "coralogix_group" "example" {
display_name = "example"
role = coralogix_custom_role.example.name
members = [coralogix_user.example.id]
}
```

Expand All @@ -40,3 +51,17 @@ resource "coralogix_user" "example" {
### Read-Only

- `id` (String) Group ID.

### Import

```sh
terraform import coralogix_group.example <group-id>
```

to get the group id you can use the following command:
```sh
curl --location --request GET 'https://ng-api-http.<region-domain>/scim/Groups' \
--header 'Authorization: Bearer <api-key>' \'
```
[region-domain table](../index.md#region-domain-table)

15 changes: 15 additions & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ Read-Only:
- `primary` (Boolean)
- `type` (String)
- `value` (String)

### Import

```sh
terraform import coralogix_user.example <user-id>
```

to get the user id you can use the following command:
```sh
curl --location --request GET 'https://ng-api-http.<region-domain>/scim/Users' \
--header 'Authorization: Bearer <api-key>' \'
```
[region-domain table](../index.md#region-domain-table)


2 changes: 1 addition & 1 deletion examples/apikeys/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
}

provider "coralogix" {
# org_key = "<ORG_KEY>"
# api_key = "<API_KEY>"
# domain = "<DOMAIN>"
}

Expand Down
14 changes: 14 additions & 0 deletions examples/custom_role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ resource "coralogix_custom_role" "example" {
parent_role = "Standard User"
permissions = ["spans.events2metrics:UpdateConfig"]
}

resource "coralogix_user" "example" {
user_name = "[email protected]"
name = {
given_name = "example"
family_name = "example"
}
}

resource "coralogix_group" "example" {
display_name = "example"
role = coralogix_custom_role.example.name
members = [coralogix_user.example.id]
}
19 changes: 15 additions & 4 deletions examples/group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ provider "coralogix" {
#env = "<add the environment you want to work at or add env variable CORALOGIX_ENV>"
}

resource "coralogix_group" "example" {
display_name = "example"
role = "Read Only"
members = [coralogix_user.example.id]
resource "coralogix_custom_role" "example" {
name = "Example custom role"
description = "This role is created with terraform!"
parent_role = "Standard User"
permissions = ["spans.events2metrics:UpdateConfig"]
}

resource "coralogix_user" "example" {
user_name = "[email protected]"
name = {
given_name = "example"
family_name = "example"
}
}

resource "coralogix_group" "example" {
display_name = "example"
role = coralogix_custom_role.example.name
members = [coralogix_user.example.id]
}

9 changes: 8 additions & 1 deletion examples/user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ provider "coralogix" {
#env = "<add the environment you want to work at or add env variable CORALOGIX_ENV>"
}

resource "coralogix_custom_role" "example" {
name = "Example custom role"
description = "This role is created with terraform!"
parent_role = "Standard User"
permissions = ["spans.events2metrics:UpdateConfig"]
}

resource "coralogix_user" "example" {
user_name = "[email protected]"
name = {
Expand All @@ -22,7 +29,7 @@ resource "coralogix_user" "example" {

resource "coralogix_group" "example" {
display_name = "example"
role = "Read Only"
role = coralogix_custom_role.example.name
members = [coralogix_user.example.id]
}

0 comments on commit 6813c99

Please sign in to comment.