Skip to content

Commit

Permalink
Merge branch 'main' into update-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
toppercodes authored Sep 18, 2024
2 parents 6dde812 + 4a16624 commit a9fb854
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 29 deletions.
64 changes: 40 additions & 24 deletions axiom/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,16 @@ func TestAccAxiomResources_basic(t *testing.T) {
Config: testAccAxiomDatasetConfig_basic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAxiomResourcesExist(client, "axiom_dataset.test"),
testAccCheckAxiomResourcesExist(client, "axiom_dataset.test_without_description"),
resource.TestCheckResourceAttr("axiom_dataset.test", "name", "terraform-provider-dataset"),
resource.TestCheckResourceAttr("axiom_dataset.test", "description", "A test dataset"),
testAccCheckAxiomResourcesExist(client, "axiom_monitor.test_monitor"),
testAccCheckAxiomResourcesExist(client, "axiom_monitor.test_monitor_without_description"),
resource.TestCheckResourceAttr("axiom_monitor.test_monitor", "name", "test monitor"),
testAccCheckAxiomResourcesExist(client, "axiom_notifier.slack_test"),
resource.TestCheckResourceAttr("axiom_notifier.slack_test", "name", "slack_test"),
testAccCheckAxiomResourcesExist(client, "axiom_token.test_token"),
resource.TestCheckResourceAttr("axiom_token.test_token", "name", "test_token"),
resource.TestCheckResourceAttr("axiom_token.test_token", "description", "test_token"),
resource.TestCheckResourceAttr("axiom_token.test_token", "expires_at", "2027-06-29T13:02:54Z"),
resource.TestCheckResourceAttr("axiom_token.test_token", "dataset_capabilities.new-dataset.ingest.0", "create"),
resource.TestCheckResourceAttr("axiom_token.test_token", "org_capabilities.api_tokens.0", "read"),
testAccCheckAxiomResourcesExist(client, "axiom_token.dataset_token"),
resource.TestCheckResourceAttr("axiom_token.dataset_token", "name", "dataset only token"),
resource.TestCheckResourceAttr("axiom_token.dataset_token", "description", "Can only access a single dataset"),
resource.TestCheckResourceAttr("axiom_token.dataset_token", "expires_at", "2027-06-29T13:02:54Z"),
resource.TestCheckResourceAttr("axiom_token.dataset_token", "dataset_capabilities.new-dataset.ingest.0", "create"),
resource.TestCheckResourceAttr("axiom_token.dataset_token", "dataset_capabilities.new-dataset.query.0", "read"),
),
},
{
Config: testAccAxiomDatasetConfig_basic(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAxiomResourcesExist(client, "axiom_dataset.test"),
resource.TestCheckResourceAttr("axiom_dataset.test", "name", "terraform-provider-dataset"),
resource.TestCheckResourceAttr("axiom_dataset.test", "description", "A test dataset"),
testAccCheckAxiomResourcesExist(client, "axiom_monitor.test_monitor"),
resource.TestCheckResourceAttr("axiom_monitor.test_monitor", "name", "test monitor"),
testAccCheckAxiomResourcesExist(client, "axiom_notifier.slack_test"),
resource.TestCheckResourceAttr("axiom_notifier.slack_test", "name", "slack_test"),
testAccCheckAxiomResourcesExist(client, "axiom_dataset.test"),
testAccCheckAxiomResourcesExist(client, "axiom_token.test_token_without_description"),
resource.TestCheckResourceAttr("axiom_token.test_token", "name", "test_token"),
resource.TestCheckResourceAttr("axiom_token.test_token", "description", "test_token"),
resource.TestCheckResourceAttr("axiom_token.test_token", "expires_at", "2027-06-29T13:02:54Z"),
Expand Down Expand Up @@ -207,6 +186,10 @@ resource "axiom_dataset" "test" {
description = "A test dataset"
}
resource "axiom_dataset" "test_without_description" {
name = "terraform-provider-dataset-without-description"
}
resource "axiom_notifier" "slack_test" {
name = "slack_test"
properties = {
Expand Down Expand Up @@ -236,6 +219,25 @@ resource "axiom_monitor" "test_monitor" {
notify_by_group = false
}
resource "axiom_monitor" "test_monitor_without_description" {
depends_on = [axiom_dataset.test, axiom_notifier.slack_test]
name = "test monitor without description"
apl_query = <<EOT
['terraform-provider-dataset']
| summarize count() by bin_auto(_time)
EOT
interval_minutes = 5
operator = "Above"
range_minutes = 5
threshold = 1
notifier_ids = [
axiom_notifier.slack_test.id
]
alert_on_no_data = false
notify_by_group = false
}
resource "axiom_monitor" "test_monitor_match_event" {
depends_on = [axiom_dataset.test, axiom_notifier.slack_test]
Expand Down Expand Up @@ -271,6 +273,20 @@ resource "axiom_token" "test_token" {
}
}
resource "axiom_token" "test_token_without_description" {
name = "test_token_without_description"
expires_at = "2027-06-29T13:02:54Z"
dataset_capabilities = {
"new-dataset" = {
ingest = ["create"],
query = ["read"]
}
}
org_capabilities = {
api_tokens = ["read"]
}
}
resource "axiom_token" "dataset_token" {
name = "dataset only token"
description = "Can only access a single dataset"
Expand Down
8 changes: 7 additions & 1 deletion axiom/resource_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,15 @@ func (r *DatasetResource) ImportState(ctx context.Context, req resource.ImportSt
}

func flattenDataset(dataset *axiom.Dataset) DatasetResourceModel {
var description types.String

if dataset.Description != "" {
description = types.StringValue(dataset.Description)
}

return DatasetResourceModel{
Name: types.StringValue(dataset.Name),
Description: types.StringValue(dataset.Description),
Description: description,
ID: types.StringValue(dataset.ID),
}
}
8 changes: 7 additions & 1 deletion axiom/resource_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,19 @@ func extractMonitorResourceModel(ctx context.Context, plan MonitorResourceModel)

func flattenMonitor(monitor *axiom.Monitor) MonitorResourceModel {
var disabledUntil types.String
var description types.String

if !monitor.DisabledUntil.IsZero() {
disabledUntil = types.StringValue(monitor.DisabledUntil.Format(time.RFC3339))
}

if monitor.Description != "" {
description = types.StringValue(monitor.Description)
}
return MonitorResourceModel{
ID: types.StringValue(monitor.ID),
Name: types.StringValue(monitor.Name),
Description: types.StringValue(monitor.Description),
Description: description,
AlertOnNoData: types.BoolValue(monitor.AlertOnNoData),
NotifyByGroup: types.BoolValue(monitor.NotifyByGroup),
APLQuery: types.StringValue(monitor.APLQuery),
Expand Down
16 changes: 13 additions & 3 deletions axiom/resource_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (r *TokenResource) ImportState(ctx context.Context, req resource.ImportStat
}

func flattenToken(ctx context.Context, token *axiom.APIToken) (TokensResourceModel, diag.Diagnostics) {
dsCapabilities, diags := flattenDatasetCapabilities(context.Background(), token.DatasetCapabilities)
dsCapabilities, diags := flattenDatasetCapabilities(ctx, token.DatasetCapabilities)
if diags.HasError() {
return TokensResourceModel{}, diags
}
Expand All @@ -531,10 +531,15 @@ func flattenToken(ctx context.Context, token *axiom.APIToken) (TokensResourceMod
return TokensResourceModel{}, diags
}

var description types.String
if token.Description != "" {
description = types.StringValue(token.Description)
}

t := TokensResourceModel{
ID: types.StringValue(token.ID),
Name: types.StringValue(token.Name),
Description: types.StringValue(token.Description),
Description: description,
DatasetCapabilities: dsCapabilities,
OrgCapabilities: orgCapabilities,
}
Expand All @@ -555,10 +560,15 @@ func flattenCreateTokenResponse(ctx context.Context, token *axiom.CreateTokenRes
if diags.HasError() {
return TokensResourceModel{}, diags
}

var description types.String
if token.Description != "" {
description = types.StringValue(token.Description)
}
t := TokensResourceModel{
ID: types.StringValue(token.ID),
Name: types.StringValue(token.Name),
Description: types.StringValue(token.Description),
Description: description,
DatasetCapabilities: dsCapabilities,
OrgCapabilities: orgCapabilities,
Token: types.StringValue(token.Token),
Expand Down

0 comments on commit a9fb854

Please sign in to comment.