From 8a762b6cd4fe634599f3e7b3ef4c4a4da8df4519 Mon Sep 17 00:00:00 2001 From: Amund Tenstad Date: Fri, 30 Apr 2021 16:34:01 +0200 Subject: [PATCH] Make port optional --- internal/provider/data_source_remotefile.go | 21 ++++++++++--------- .../provider/data_source_remotefile_test.go | 5 +++++ internal/provider/resource_remotefile.go | 21 ++++++++++--------- internal/provider/resource_remotefile_test.go | 5 +++++ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/internal/provider/data_source_remotefile.go b/internal/provider/data_source_remotefile.go index 3ea6ad4..775c443 100644 --- a/internal/provider/data_source_remotefile.go +++ b/internal/provider/data_source_remotefile.go @@ -20,6 +20,17 @@ func dataSourceRemotefile() *schema.Resource { Description: "Connection to host where files are located.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Required: true, + Description: "The target host.", + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Default: 22, + Description: "The ssh port to the target host.", + }, "username": { Type: schema.TypeString, Required: true, @@ -31,16 +42,6 @@ func dataSourceRemotefile() *schema.Resource { Sensitive: true, Description: "The private key used to login to the target host.", }, - "host": { - Type: schema.TypeString, - Required: true, - Description: "The target host.", - }, - "port": { - Type: schema.TypeInt, - Required: true, - Description: "The ssh port to the target host.", - }, }, }, }, diff --git a/internal/provider/data_source_remotefile_test.go b/internal/provider/data_source_remotefile_test.go index 001975d..9d553f7 100644 --- a/internal/provider/data_source_remotefile_test.go +++ b/internal/provider/data_source_remotefile_test.go @@ -34,6 +34,11 @@ func TestAccDataSourceRemotefile(t *testing.T) { const testAccDataSourceRemotefile = ` data "remotefile" "bar" { + conn { + host = "localhost" + username = "root" + private_key = "" + } path = "/tmp/bar.txt" } ` diff --git a/internal/provider/resource_remotefile.go b/internal/provider/resource_remotefile.go index 7c4ca5b..334f95f 100644 --- a/internal/provider/resource_remotefile.go +++ b/internal/provider/resource_remotefile.go @@ -25,6 +25,17 @@ func resourceRemotefile() *schema.Resource { Description: "Connection to host where files are located.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "host": { + Type: schema.TypeString, + Required: true, + Description: "The target host.", + }, + "port": { + Type: schema.TypeInt, + Optional: true, + Default: 22, + Description: "The ssh port to the target host.", + }, "username": { Type: schema.TypeString, Required: true, @@ -36,16 +47,6 @@ func resourceRemotefile() *schema.Resource { Sensitive: true, Description: "The private key used to login to the target host.", }, - "host": { - Type: schema.TypeString, - Required: true, - Description: "The target host.", - }, - "port": { - Type: schema.TypeInt, - Required: true, - Description: "The ssh port to the target host.", - }, }, }, }, diff --git a/internal/provider/resource_remotefile_test.go b/internal/provider/resource_remotefile_test.go index 3c8235f..897f83b 100644 --- a/internal/provider/resource_remotefile_test.go +++ b/internal/provider/resource_remotefile_test.go @@ -25,6 +25,11 @@ func TestAccResourceRemotefile(t *testing.T) { const testAccResourceRemotefile = ` resource "remotefile" "foo" { + conn { + host = "localhost" + username = "root" + private_key = "" + } path = "/tmp/foo.txt" content = "bar" permissions = "0777"