diff --git a/internal/provider/testdata/SecurityGroup_invalid_rules.cassette.rand_id b/internal/provider/testdata/SecurityGroup_invalid_rules.cassette.rand_id index d8d291b..b1d35ca 100644 --- a/internal/provider/testdata/SecurityGroup_invalid_rules.cassette.rand_id +++ b/internal/provider/testdata/SecurityGroup_invalid_rules.cassette.rand_id @@ -1 +1 @@ -p8mwdmjy061s \ No newline at end of file +begv003ejaf9 \ No newline at end of file diff --git a/internal/v6provider/resource_ip_test.go b/internal/v6provider/resource_ip_test.go index dcdebfa..6173220 100644 --- a/internal/v6provider/resource_ip_test.go +++ b/internal/v6provider/resource_ip_test.go @@ -125,6 +125,67 @@ func TestAccKatapultIP_minimal(t *testing.T) { }) } +func TestAccKatapultIP_import_by_addr(t *testing.T) { + tt := newTestTools(t) + + res, err := tt.Meta.Core.GetDataCenterDefaultNetworkWithResponse(tt.Ctx, + &core.GetDataCenterDefaultNetworkParams{ + DataCenterPermalink: &tt.Meta.confDataCenter, + }) + require.NoError(t, err) + require.NotNil(t, res) + require.NotNil(t, res.JSON200) + + network := res.JSON200.Network + require.NotNil(t, network.Id) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: tt.ProviderFactories, + + CheckDestroy: testAccCheckKatapultIPDestroy(tt), + Steps: []resource.TestStep{ + { + Config: `resource "katapult_ip" "web" {}`, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKatapultIPAttrs(tt, "katapult_ip.web"), + resource.TestCheckResourceAttr( + "katapult_ip.web", "network_id", *network.Id, + ), + resource.TestMatchResourceAttr( + "katapult_ip.web", + "address", regexp.MustCompile( + `^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$`, + ), + ), + resource.TestCheckResourceAttr( + "katapult_ip.web", "version", "4", + ), + resource.TestCheckResourceAttr( + "katapult_ip.web", "vip", "false", + ), + resource.TestCheckResourceAttr( + "katapult_ip.web", "label", "", + ), + ), + }, + { + ResourceName: "katapult_ip.web", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + rs := s.RootModule().Resources["katapult_ip.web"] + if rs == nil { + return "", fmt.Errorf("resource not found") + } + + return rs.Primary.Attributes["address"], nil + }, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccKatapultIP_ipv4(t *testing.T) { tt := newTestTools(t) diff --git a/internal/v6provider/testdata/IP_import_by_addr.cassette.yaml b/internal/v6provider/testdata/IP_import_by_addr.cassette.yaml new file mode 100644 index 0000000..45946e8 --- /dev/null +++ b/internal/v6provider/testdata/IP_import_by_addr.cassette.yaml @@ -0,0 +1,420 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/data_centers/:data_center/default_network?data_center%5Bpermalink%5D=uk-lon-01 + method: GET + response: + body: '{"network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01"}}}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "181" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:28 GMT + Etag: + - W/"d60d47b2ba0b179327bb89a97b1c0e77" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "991" + X-Request-Id: + - 0dd19ebc-9efd-4054-9c04-e7bae555706f + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/data_centers/:data_center/default_network?data_center%5Bpermalink%5D=uk-lon-01 + method: GET + response: + body: '{"network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01"}}}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "181" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:28 GMT + Etag: + - W/"d60d47b2ba0b179327bb89a97b1c0e77" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "990" + X-Request-Id: + - 9e0078a5-1503-4fb6-ab13-27106cd941ea + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"network":{"id":"netw_gVRkZdSKczfNg34P"},"organization":{"sub_domain":"terraform-acc-test"},"version":"ipv4"}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/organizations/:organization/ip_addresses + method: POST + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null}}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "543" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:28 GMT + Etag: + - W/"84dd41fedbf56cd20b0ef169ab32024b" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "989" + X-Request-Id: + - c94c64dd-dc7e-4af3-a5a6-15e5a8640f7d + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Bid%5D=ip_ax6jM4AVdKNM0EZP + method: GET + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null},"allocation":null}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "561" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:28 GMT + Etag: + - W/"a2e9216ddf3314ce98f56b793c27c0d4" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "988" + X-Request-Id: + - 2100b8d3-48bb-4f66-90fe-fa233e87ef06 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Bid%5D=ip_ax6jM4AVdKNM0EZP + method: GET + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null},"allocation":null}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "561" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:28 GMT + Etag: + - W/"a2e9216ddf3314ce98f56b793c27c0d4" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "987" + X-Request-Id: + - 5bd6c7b6-0581-4e87-874c-c86dd3afc9e8 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Bid%5D=ip_ax6jM4AVdKNM0EZP + method: GET + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null},"allocation":null}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "561" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:29 GMT + Etag: + - W/"a2e9216ddf3314ce98f56b793c27c0d4" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "986" + X-Request-Id: + - 83ed9b11-235d-41c0-9f55-e66edb3fcc1b + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Baddress%5D=185.44.253.28 + method: GET + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null},"allocation":null}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "561" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:29 GMT + Etag: + - W/"a2e9216ddf3314ce98f56b793c27c0d4" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "985" + X-Request-Id: + - b432b1f9-9f6c-4bc9-b638-ddd25728ce72 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Bid%5D=ip_ax6jM4AVdKNM0EZP + method: GET + response: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP","address":"185.44.253.28","reverse_dns":"185-44-253-28.rdns.katapult.io","vip":false,"label":null,"address_with_mask":"185.44.253.28/22","network":{"id":"netw_gVRkZdSKczfNg34P","name":"Public + Network","permalink":"uk-lon-01-public","data_center":{"id":"loc_UUhPmoCbpic6UX0Y","name":"London","permalink":"uk-lon-01","country":{"id":"ctry_6AO9tYYugvTGnd5b","name":"United + Kingdom","iso_code2":"GB","iso_code3":"GBR","time_zone":"Europe/London","eu":false}}},"allocation_id":null,"allocation_type":null},"allocation":null}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "561" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:29 GMT + Etag: + - W/"a2e9216ddf3314ce98f56b793c27c0d4" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "984" + X-Request-Id: + - 033bcc76-5000-4b43-8dec-223228332ded + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"ip_address":{"id":"ip_ax6jM4AVdKNM0EZP"}}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - "2" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:29 GMT + Etag: + - W/"44136fa355b3678a1146ad16f7e8649e" + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "983" + X-Request-Id: + - ff5c4eeb-1147-4fc4-ae3f-470111778050 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - Terraform/ (+https://www.terraform.io) Terraform-Plugin-Framework terraform-provider-katapult + url: https://api.katapult.io/core/v1/ip_addresses/:ip_address?ip_address%5Bid%5D=ip_ax6jM4AVdKNM0EZP + method: GET + response: + body: '{"error":{"code":"ip_address_not_found","description":"No IP addresses + were found matching any of the criteria provided in the arguments","detail":{}}}' + headers: + Access-Control-Allow-Headers: + - Authorization, Content-Type + Access-Control-Allow-Methods: + - GET, POST, PUT, PATCH, DELETE, OPTIONS + Access-Control-Allow-Origin: + - '*' + Cache-Control: + - no-cache + Content-Length: + - "151" + Content-Type: + - application/json + Date: + - Mon, 12 Aug 2024 14:53:30 GMT + Strict-Transport-Security: + - max-age=63072000; includeSubDomains + Vary: + - Accept-Encoding + X-Api-Schema: + - json-error + X-Ratelimit-Permitted: + - "1000" + X-Ratelimit-Remaining: + - "982" + X-Request-Id: + - 943d5ada-b166-47e0-9172-f921cbc88a32 + status: 404 Not Found + code: 404 + duration: ""