vpc.tftest.hcl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. mock_provider "digitalocean" {}
  2. variables {
  3. layer = "foundation"
  4. region = "tor1"
  5. ip_range = "10.78.0.0/24"
  6. }
  7. run "name_follows_layer_region_role" {
  8. command = plan
  9. assert {
  10. condition = digitalocean_vpc.this.name == "foundation-tor1-vpc"
  11. error_message = "VPC name must be <layer>-<region>-vpc."
  12. }
  13. assert {
  14. condition = digitalocean_vpc.this.region == "tor1"
  15. error_message = "VPC must be created in the requested region."
  16. }
  17. }
  18. run "rejects_public_range" {
  19. command = plan
  20. variables {
  21. ip_range = "8.8.8.0/24"
  22. }
  23. expect_failures = [var.ip_range]
  24. }
  25. run "rejects_malformed_range" {
  26. command = plan
  27. variables {
  28. ip_range = "not-a-cidr"
  29. }
  30. expect_failures = [var.ip_range]
  31. }
  32. # resource_key goes into the name; the region argument always takes the region.
  33. run "resource_key_changes_the_name_not_the_region" {
  34. command = plan
  35. variables {
  36. resource_key = "tor1-b"
  37. }
  38. assert {
  39. condition = digitalocean_vpc.this.name == "foundation-tor1-b-vpc"
  40. error_message = "A resource_key must replace the region in the name."
  41. }
  42. assert {
  43. condition = digitalocean_vpc.this.region == "tor1"
  44. error_message = "The VPC must still be created in the real region."
  45. }
  46. }
  47. run "an_empty_resource_key_means_the_region" {
  48. command = plan
  49. variables {
  50. resource_key = ""
  51. }
  52. assert {
  53. condition = digitalocean_vpc.this.name == "foundation-tor1-vpc"
  54. error_message = "An empty resource_key must leave the name as before."
  55. }
  56. }
  57. run "rejects_a_bad_resource_key" {
  58. command = plan
  59. variables {
  60. resource_key = "Not Valid"
  61. }
  62. expect_failures = [var.resource_key]
  63. }