From 70f4544dec9521cd693e13d5eb70fc2af6236310 Mon Sep 17 00:00:00 2001 From: Josh Purvis Date: Sun, 9 Apr 2017 22:52:15 -0400 Subject: [PATCH] Add monitoring option to digitalocean provider --- .../resource_digitalocean_droplet.go | 9 +++++ .../resource_digitalocean_droplet_test.go | 33 +++++++++++++++++++ .../docs/providers/do/r/droplet.html.markdown | 2 ++ 3 files changed, 44 insertions(+) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index 76212d579be7..bfb64d749306 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -107,6 +107,11 @@ func resourceDigitalOceanDroplet() *schema.Resource { Optional: true, }, + "monitoring": { + Type: schema.TypeBool, + Optional: true, + }, + "ipv4_address": { Type: schema.TypeString, Computed: true, @@ -169,6 +174,10 @@ func resourceDigitalOceanDropletCreate(d *schema.ResourceData, meta interface{}) opts.PrivateNetworking = attr.(bool) } + if attr, ok := d.GetOk("monitoring"); ok { + opts.Monitoring = attr.(bool) + } + if attr, ok := d.GetOk("user_data"); ok { opts.UserData = attr.(string) } diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go index 1c3d5601cdaf..3349cd6cb8cf 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go @@ -294,6 +294,27 @@ func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) { }) } +func testAccDigitalOceanDroplet_Monitoring(t *testing.T) { + var droplet godo.Droplet + rInt := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDigitalOceanDropletDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckDigitalOceanDropletConfig_Monitoring(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet), + resource.TestCheckResourceAttr( + "digitalocean_droplet.foobar", "monitoring", "true"), + ), + }, + }, + }) +} + func testAccCheckDigitalOceanDropletDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*godo.Client) @@ -584,4 +605,16 @@ resource "digitalocean_droplet" "foobar" { `, rInt) } +func testAccCheckDigitalOceanDropletConfig_Monitoring(rInt int) string { + return fmt.Sprintf(` +resource "digitalocean_droplet" "foobar" { + name = "foo-%d" + size = "1gb" + image = "centos-7-x64" + region = "nyc3" + monitoring = true +} +`, rInt) +} + var testAccValidPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR` diff --git a/website/source/docs/providers/do/r/droplet.html.markdown b/website/source/docs/providers/do/r/droplet.html.markdown index a3b0260009f9..0084f79f3310 100644 --- a/website/source/docs/providers/do/r/droplet.html.markdown +++ b/website/source/docs/providers/do/r/droplet.html.markdown @@ -34,6 +34,8 @@ The following arguments are supported: * `size` - (Required) The instance size to start * `backups` - (Optional) Boolean controlling if backups are made. Defaults to false. +* `monitoring` - (Optional) Boolean controlling whether monitoring agent is installed. + Defaults to false. * `ipv6` - (Optional) Boolean controlling if IPv6 is enabled. Defaults to false. * `private_networking` - (Optional) Boolean controlling if private networks are enabled. Defaults to false.