diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 93cfbc7..9836b3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,11 @@ name: Tests + +env: + TF_ACC: "1" + CLOUDCONNEXA_TEST_ORGANIZATION: ${{ secrets.CLOUDCONNEXA_TEST_ORGANIZATION }} + CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }} + CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }} + on: pull_request: branches: @@ -38,6 +45,7 @@ jobs: # run acceptance tests in a matrix with Terraform core versions test: name: Matrix Test + environment: TestingEnv needs: build runs-on: ubuntu-latest timeout-minutes: 15 @@ -64,10 +72,5 @@ jobs: go mod download - name: TF acceptance tests timeout-minutes: 10 - env: - TF_ACC: "1" - CLOUDCONNEXA_TEST_ORGANIZATION: "terraform-community" - CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CVPN_CLIENT_ID }} - CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CVPN_CLIENT_SECRET }} run: | go test -v -cover ./cloudconnexa diff --git a/cloudconnexa/resource_connector_test.go b/cloudconnexa/resource_connector_test.go index 4df8102..7a27b45 100644 --- a/cloudconnexa/resource_connector_test.go +++ b/cloudconnexa/resource_connector_test.go @@ -2,9 +2,10 @@ package cloudconnexa import ( "fmt" - "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" "testing" + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -78,7 +79,7 @@ provider "cloudconnexa" { } resource "cloudconnexa_connector" "test" { - name = "%s" + name = "%[2]s" vpn_region_id = "us-west-1" network_item_type = "HOST" network_item_id = "example_network_item_id" diff --git a/cloudconnexa/resource_dns_record.go b/cloudconnexa/resource_dns_record.go index 61dd85c..e7fd1d5 100644 --- a/cloudconnexa/resource_dns_record.go +++ b/cloudconnexa/resource_dns_record.go @@ -34,17 +34,22 @@ func resourceDnsRecord() *schema.Resource { Description: "The description for the UI. Defaults to `Managed by Terraform`.", }, "ip_v4_addresses": { - Type: schema.TypeList, - Optional: true, + Type: schema.TypeList, + Optional: true, + AtLeastOneOf: []string{"ip_v4_addresses", "ip_v6_addresses"}, + MinItems: 1, Elem: &schema.Schema{ + Type: schema.TypeString, ValidateFunc: validation.IsIPv4Address, }, Description: "The list of IPV4 addresses to which this record will resolve.", }, "ip_v6_addresses": { - Type: schema.TypeList, - Optional: true, + Type: schema.TypeList, + Optional: true, + AtLeastOneOf: []string{"ip_v4_addresses", "ip_v6_addresses"}, + MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.IsIPv6Address, diff --git a/cloudconnexa/resource_dns_record_test.go b/cloudconnexa/resource_dns_record_test.go index 26252f9..e56662e 100644 --- a/cloudconnexa/resource_dns_record_test.go +++ b/cloudconnexa/resource_dns_record_test.go @@ -1,8 +1,10 @@ package cloudconnexa import ( + "errors" "fmt" "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -32,6 +34,36 @@ func TestAccCloudConnexaDnsRecord_basic(t *testing.T) { }) } +func TestAccCloudConnexaDnsRecord_noIPs(t *testing.T) { + expectedErr, _ := regexp.Compile("one of `ip_v4_addresses,ip_v6_addresses` must be specified") + domainName := "test.cloudconnexa.com" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCloudConnexaDnsRecordConfigWithoutIPs(domainName), + ExpectError: expectedErr, + }, + }, + }) +} + +func TestAccCloudConnexaDnsRecord_IPsArrayIsEmpty(t *testing.T) { + expectedErr, _ := regexp.Compile("Attribute ip_v4_addresses requires 1 item minimum, but config has only 0") + domainName := "test.cloudconnexa.com" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCloudConnexaDnsRecordConfigIPv4Empty(domainName), + ExpectError: expectedErr, + }, + }, + }) +} + func testAccCheckCloudConnexaDnsRecordDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*cloudconnexa.Client) @@ -43,8 +75,8 @@ func testAccCheckCloudConnexaDnsRecordDestroy(s *terraform.State) error { recordId := rs.Primary.ID r, err := client.DnsRecords.GetDnsRecord(recordId) - if err != nil { - return err + if !errors.Is(err, cloudconnexa.ErrDnsRecordNotFound) { + return nil } if r != nil { @@ -69,3 +101,30 @@ resource "cloudconnexa_dns_record" "test" { } `, testCloudID, domainName) } + +func testAccCloudConnexaDnsRecordConfigWithoutIPs(domainName string) string { + return fmt.Sprintf(` +provider "cloudconnexa" { + base_url = "https://%[1]s.api.openvpn.com" +} + +resource "cloudconnexa_dns_record" "test" { + domain = "%[2]s" + description = "test description" +} +`, testCloudID, domainName) +} + +func testAccCloudConnexaDnsRecordConfigIPv4Empty(domainName string) string { + return fmt.Sprintf(` +provider "cloudconnexa" { + base_url = "https://%[1]s.api.openvpn.com" +} + +resource "cloudconnexa_dns_record" "test" { + domain = "%[2]s" + description = "test description" + ip_v4_addresses = [] +} +`, testCloudID, domainName) +} diff --git a/cloudconnexa/resource_route_test.go b/cloudconnexa/resource_route_test.go index a5a085a..a1d4edd 100644 --- a/cloudconnexa/resource_route_test.go +++ b/cloudconnexa/resource_route_test.go @@ -119,7 +119,7 @@ resource "cloudconnexa_network" "test" { vpn_region_id = "fi-hel" } default_route { - subnet = "10.1.2.0/24" + subnet = "10.1.1.0/24" type = "IP_V4" } } diff --git a/cloudconnexa/resource_service_test.go b/cloudconnexa/resource_service_test.go index 412c9ae..4913047 100644 --- a/cloudconnexa/resource_service_test.go +++ b/cloudconnexa/resource_service_test.go @@ -3,9 +3,10 @@ package cloudconnexa import ( "errors" "fmt" + "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" - "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -81,30 +82,30 @@ func testAccCheckCloudConnexaServiceDestroy(state *terraform.State) error { func testAccCloudConnexaServiceConfig(service cloudconnexa.IPService, networkName string) string { return fmt.Sprintf(` provider "cloudconnexa" { - base_url = "https://%s.api.openvpn.com" + base_url = "https://%[1]s.api.openvpn.com" } resource "cloudconnexa_network" "test" { - name = "%s" + name = "%[2]s" description = "test" default_connector { - name = "%s" + name = "%[3]s" vpn_region_id = "fi-hel" } default_route { - value = "10.1.2.0/24" + subnet = "10.1.2.0/24" type = "IP_V4" } } resource "cloudconnexa_ip_service" "test" { - name = "%s" + name = "%[4]s" type = "SERVICE_DESTINATION" description = "test" network_item_type = "NETWORK" network_item_id = cloudconnexa_network.test.id - routes = ["test.ua" ] + routes = ["10.1.2.1/32" ] config { service_types = ["ANY"] } diff --git a/cloudconnexa/resource_user_group_test.go b/cloudconnexa/resource_user_group_test.go index abc19b6..23e6891 100644 --- a/cloudconnexa/resource_user_group_test.go +++ b/cloudconnexa/resource_user_group_test.go @@ -4,9 +4,10 @@ import ( "encoding/json" "errors" "fmt" - "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" "testing" + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -96,11 +97,11 @@ func testAccCloudConnexaUserGroupConfig(userGroup cloudconnexa.UserGroup) string return fmt.Sprintf(` provider "cloudconnexa" { - base_url = "https://%s.api.openvpn.com" + base_url = "https://%[1]s.api.openvpn.com" } resource "cloudconnexa_user_group" "test" { - name = "%s" - vpn_region_ids = %s + name = "%[2]s" + vpn_region_ids = %[3]s } `, testCloudID, userGroup.Name, idsStr) diff --git a/cloudconnexa/resource_user_test.go b/cloudconnexa/resource_user_test.go index 7095b73..257b09f 100644 --- a/cloudconnexa/resource_user_test.go +++ b/cloudconnexa/resource_user_test.go @@ -3,9 +3,10 @@ package cloudconnexa import ( "errors" "fmt" - "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" "testing" + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -106,13 +107,21 @@ func testAccCloudConnexaUserImportStateIdFunc(n string) resource.ImportStateIdFu func testAccCloudConnexaUserConfig(user cloudconnexa.User) string { return fmt.Sprintf(` provider "cloudconnexa" { - base_url = "https://%s.api.openvpn.com" + base_url = "https://%[1]s.api.openvpn.com" } + +resource "cloudconnexa_user_group" "test" { + name = "test-group" + vpn_region_ids = ["eu-central-1"] + connect_auth = "AUTH" +} + resource "cloudconnexa_user" "test" { - username = "%s" - email = "%s" - first_name = "%s" - last_name = "%s" + username = "%[2]s" + email = "%[3]s" + first_name = "%[4]s" + last_name = "%[5]s" + group_id = cloudconnexa_user_group.test.id } `, testCloudID, user.Username, user.Email, user.FirstName, user.LastName) } diff --git a/go.mod b/go.mod index 036d6c8..4682c50 100644 --- a/go.mod +++ b/go.mod @@ -8,13 +8,13 @@ require ( github.com/gruntwork-io/terratest v0.47.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13 + github.com/openvpn/cloudconnexa-go-client/v2 v2.0.14 github.com/stretchr/testify v1.9.0 ) require ( cloud.google.com/go v0.112.0 // indirect - cloud.google.com/go/compute v1.24.0 // indirect +cloud.google.com/go/compute v1.24.0 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.36.0 // indirect @@ -89,7 +89,7 @@ require ( golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.5.0 // indirect + golang.org/x/time v0.6.0 // indirect golang.org/x/tools v0.20.0 // indirect google.golang.org/api v0.162.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index bb2908a..895c0a3 100644 --- a/go.sum +++ b/go.sum @@ -485,8 +485,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= -github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13 h1:Bm47oT/O+CwXdwUu84NZZXETZCo/9Th3Cx+EGUXvyPU= -github.com/openvpn/cloudconnexa-go-client/v2 v2.0.13/go.mod h1:udq5IDkgXvMO6mQUEFsLHzEyGGAduhO0jJvlb9f4JkE= +github.com/openvpn/cloudconnexa-go-client/v2 v2.0.14 h1:rEQAt3MLLIe++dAMG64FpUgS1ZHUM/k77QtJ0GyfpZ0= +github.com/openvpn/cloudconnexa-go-client/v2 v2.0.14/go.mod h1:WJZU+oOwHUYoO7Q2tFnGavKGbhrAvo8OEgvvr9EEtCw= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -797,8 +797,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=