Skip to content

Commit

Permalink
Merge pull request #45 from appoptics/upgrade-to-0.12
Browse files Browse the repository at this point in the history
Update to 0.13, update deps, and fix alert updates.
  • Loading branch information
pcn authored Aug 18, 2020
2 parents 6b5a242 + 5340bbb commit e872a18
Show file tree
Hide file tree
Showing 2,052 changed files with 956 additions and 732,759 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ website/node_modules
*.iml

website/vendor
vendor/

# Test exclusions
!command/test-fixtures/**/*.tfstate
Expand Down
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* 2020-08-17: Updating to terraform 0.13 library to accommodate 0.12+ versions of terraform

In this update, metrics now require a "type" argument to reflect the
type of the metric as either "gauge" or "composite"'
15 changes: 9 additions & 6 deletions appoptics/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
} else {
url = "https://api.appoptics.com/v1/"
}

client := appoptics.NewClient(d.Get("token").(string),
appoptics.BaseURLClientOption(url),
appoptics.SetDebugMode(),
)
return client, nil
if do_http_debug := os.Getenv("TF_AO_DEBUG"); do_http_debug != "" {
return appoptics.NewClient(d.Get("token").(string),
appoptics.BaseURLClientOption(url),
appoptics.SetDebugMode(),
), nil
} else {
return appoptics.NewClient(d.Get("token").(string),
appoptics.BaseURLClientOption(url)), nil
}
}
3 changes: 3 additions & 0 deletions appoptics/resource_appoptics_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ func resourceAppOpticsAlertUpdate(d *schema.ResourceData, meta interface{}) erro
alert := alertToAlertRequest(theAlert)
alert.ID = int(id)

if d.HasChange("name") {
alert.Name = d.Get("name").(string)
}
if d.HasChange("description") {
alert.Description = d.Get("description").(string)
}
Expand Down
12 changes: 6 additions & 6 deletions appoptics/resource_appoptics_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ resource "appoptics_alert" "foobar" {

func testAccCheckAppOpticsAlertConfigFull(name string) string {
return fmt.Sprintf(`
resource "appoptics_service" "foobar" {
resource "appoptics_notification_service" "foobar" {
title = "Foo Bar"
type = "mail"
settings = <<EOF
Expand All @@ -325,7 +325,7 @@ EOF
resource "appoptics_alert" "foobar" {
name = "%s"
description = "A Test Alert"
services = [ "${appoptics_service.foobar.id}" ]
services = [ "${appoptics_notification_service.foobar.id}" ]
condition {
type = "above"
threshold = 10
Expand All @@ -337,7 +337,7 @@ resource "appoptics_alert" "foobar" {
values = ["host1", "host2"]
}
}
attributes {
attributes = {
runbook_url = "https://www.youtube.com/watch?v=oHg5SJYRHA0"
}
rearm_seconds = 300
Expand All @@ -346,7 +346,7 @@ resource "appoptics_alert" "foobar" {

func testAccCheckAppOpticsAlertConfigFullUpdate(name string) string {
return fmt.Sprintf(`
resource "appoptics_service" "foobar" {
resource "appoptics_notification_service" "foobar" {
title = "Foo Bar"
type = "mail"
settings = <<EOF
Expand All @@ -359,13 +359,13 @@ EOF
resource "appoptics_alert" "foobar" {
name = "%s"
description = "A Test Alert"
services = [ "${appoptics_service.foobar.id}" ]
services = [ "${appoptics_notification_service.foobar.id}" ]
condition {
type = "above"
threshold = 10
metric_name = "system.cpu.utilization"
}
attributes {
attributes = {
runbook_url = "https://www.youtube.com/watch?v=oHg5SJYRHA0"
}
rearm_seconds = 1200
Expand Down
2 changes: 1 addition & 1 deletion appoptics/resource_appoptics_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func resourceAppOpticsMetric() *schema.Resource {
},
"type": {
Type: schema.TypeString,
Optional: true,
Required: true,
},
"display_name": {
Type: schema.TypeString,
Expand Down
2 changes: 2 additions & 0 deletions appoptics/resource_appoptics_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func testAccCheckAppOpticsMetricExists(n string, metric *appoptics.Metric) resou
func gaugeMetricConfig(name, desc string) string {
return strings.TrimSpace(fmt.Sprintf(`
resource "appoptics_metric" "foobar" {
type = "gauge"
name = "%s"
description = "%s"
attributes {
Expand All @@ -175,6 +176,7 @@ func gaugeMetricConfig(name, desc string) string {
func compositeMetricConfig(name, typ, desc string) string {
return strings.TrimSpace(fmt.Sprintf(`
resource "appoptics_metric" "foobar" {
type = "composite"
name = "%s"
description = "%s"
composite = "s(\"librato.cpu.percent.user\", {\"environment\" : \"prod\", \"service\": \"api\"})"
Expand Down
18 changes: 9 additions & 9 deletions appoptics/resource_appoptics_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestAccAppOpticsServiceBasic(t *testing.T) {
resource.TestStep{
Config: testAccCheckAppOpticsServiceConfigBasic,
Check: resource.ComposeTestCheckFunc(
testAccCheckAppOpticsServiceExists("appoptics_service.foobar", &service),
testAccCheckAppOpticsServiceExists("appoptics_notification_service.foobar", &service),
resource.TestCheckResourceAttr(
"appoptics_service.foobar", "title", "Foo Bar"),
"appoptics_notification_service.foobar", "title", "Foo Bar"),
),
},
},
Expand All @@ -41,17 +41,17 @@ func TestAccAppOpticsServiceUpdated(t *testing.T) {
resource.TestStep{
Config: testAccCheckAppOpticsServiceConfigBasic,
Check: resource.ComposeTestCheckFunc(
testAccCheckAppOpticsServiceExists("appoptics_service.foobar", &service),
testAccCheckAppOpticsServiceExists("appoptics_notification_service.foobar", &service),
resource.TestCheckResourceAttr(
"appoptics_service.foobar", "title", "Foo Bar"),
"appoptics_notification_service.foobar", "title", "Foo Bar"),
),
},
resource.TestStep{
Config: testAccCheckAppOpticsServiceConfigNewValue,
Check: resource.ComposeTestCheckFunc(
testAccCheckAppOpticsServiceExists("appoptics_service.foobar", &service),
testAccCheckAppOpticsServiceExists("appoptics_notification_service.foobar", &service),
resource.TestCheckResourceAttr(
"appoptics_service.foobar", "title", "Bar Baz"),
"appoptics_notification_service.foobar", "title", "Bar Baz"),
),
},
},
Expand All @@ -62,7 +62,7 @@ func testAccCheckAppOpticsServiceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*appoptics.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != "appoptics_service" {
if rs.Type != "appoptics_notification_service" {
continue
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func testAccCheckAppOpticsServiceExists(n string, service *appoptics.Service) re
}

const testAccCheckAppOpticsServiceConfigBasic = `
resource "appoptics_service" "foobar" {
resource "appoptics_notification_service" "foobar" {
title = "Foo Bar"
type = "mail"
settings = <<EOF
Expand All @@ -126,7 +126,7 @@ EOF
}`

const testAccCheckAppOpticsServiceConfigNewValue = `
resource "appoptics_service" "foobar" {
resource "appoptics_notification_service" "foobar" {
title = "Bar Baz"
type = "mail"
settings = <<EOF
Expand Down
65 changes: 34 additions & 31 deletions example.tf → example-0.11.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// This example is for the 0.11 terraform-compatible version
// of the provider.

// Used to identify all things made in integration test runs
variable "tf-name-fragment" {
type = "string"
type = "string"
default = "tf_provider_test"
}

variable "test-metric-name" {
type = "string"
type = "string"
default = "tf_provider_test.cpu.percent.used" // can't interpolate into variables
}

Expand All @@ -26,9 +29,9 @@ resource "appoptics_dashboard" "test_dashboard" {
//
// Notification Service
//
resource "appoptics_notification_service" "test_service"{
title = "${var.tf-name-fragment} Email Notification Service"
type = "mail"
resource "appoptics_notification_service" "test_service" {
title = "${var.tf-name-fragment} Email Notification Service"
type = "mail"
settings = <<EOF
{
"addresses": "[email protected]"
Expand All @@ -39,40 +42,40 @@ EOF
//
// Metric
//
resource "appoptics_metric" "test_metric"{
name = "${var.test-metric-name}"
resource "appoptics_metric" "test_metric" {
name = "${var.test-metric-name}"
display_name = "Terraform Test CPU Utilization"
period = 60
type = "gauge"
period = 60
type = "gauge"
attributes = {
color = "#A3BE8C"
summarize_function = "average"
display_max = 100.0
display_units_long = "CPU Utilization Percent"
color = "#A3BE8C"
summarize_function = "average"
display_max = 100.0
display_units_long = "CPU Utilization Percent"
display_units_short = "cpu %"
}
}

//
// Chart
//
resource "appoptics_dashboard_chart" "test_chart"{
space_id = "${appoptics_dashboard.test_dashboard.id}"
name = "Test Chart"
resource "appoptics_dashboard_chart" "test_chart" {
space_id = "${appoptics_dashboard.test_dashboard.id}"
name = "Test Chart"
depends_on = ["appoptics_metric.test_metric"]
min = 0
max = 100
label = "Used"
min = 0
max = 100
label = "Used"

stream {
metric = "${appoptics_metric.test_metric.name}"
color = "#fa7268"
metric = "${appoptics_metric.test_metric.name}"
color = "#fa7268"
units_short = "%"
units_long = "Percentage used"
units_long = "Percentage used"

tags = [{
name = "environment"
values = ["staging"]
name = "environment"
values = ["staging"]
}]
}
}
Expand All @@ -81,17 +84,17 @@ resource "appoptics_dashboard_chart" "test_chart"{
// Alert
//
resource "appoptics_alert" "test_alert" {
name = "${var.tf-name-fragment}.Alert"
description = "Managed by Terraform"
name = "${var.tf-name-fragment}.Alert"
description = "Managed by Terraform"
rearm_seconds = 10800

depends_on = ["appoptics_metric.test_metric"]

condition {
type = "above"
threshold = 0
metric_name = "${var.test-metric-name}"
duration = 60
type = "above"
threshold = 0
metric_name = "${var.test-metric-name}"
duration = 60
summary_function = "sum"

tag {
Expand All @@ -107,4 +110,4 @@ resource "appoptics_alert" "test_alert" {
}

}
}
}
Loading

0 comments on commit e872a18

Please sign in to comment.