-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add vrack data source #854
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceVrack() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceVrackRead, | ||
Schema: map[string]*schema.Schema{ | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
// Here come all the computed items | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"iam": { | ||
Type: schema.TypeMap, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVrackRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
serviceName := d.Get("service_name").(string) | ||
vrack := &Vrack{} | ||
err := config.OVHClient.Get( | ||
fmt.Sprintf( | ||
"/vrack/%s", | ||
serviceName, | ||
), | ||
&vrack, | ||
) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error calling /vrack/%s:\n\t %q", serviceName, err) | ||
} | ||
|
||
d.SetId(serviceName) | ||
d.Set("name", vrack.Name) | ||
d.Set("description", vrack.Description) | ||
iam := make(map[string]string) | ||
iam["id"] = vrack.IamResourceDetails.Id | ||
iam["urn"] = vrack.IamResourceDetails.URN | ||
d.Set("iam", iam) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ovh | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestAccVrackDataSource_basic(t *testing.T) { | ||
vrack := os.Getenv("OVH_VRACK_SERVICE_TEST") | ||
config := fmt.Sprintf(testAccVrackDatasourceConfig_Basic, vrack) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheckVrack(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_vrack.vrack", "id", vrack), | ||
resource.TestCheckResourceAttr( | ||
"data.ovh_vrack.vrack", "service_name", vrack), | ||
resource.TestCheckResourceAttrSet( | ||
"data.ovh_vrack.vrack", "iam"), | ||
resource.TestCheckResourceAttrSet( | ||
"data.ovh_vrack.vrack", "name"), | ||
resource.TestCheckResourceAttrSet( | ||
"data.ovh_vrack.vrack", "description"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccVrackDatasourceConfig_Basic = ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you move this definition in the test func itself to avoid the global variable ? |
||
data "ovh_vrack" "vrack" { | ||
service_name = "%s" | ||
} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,6 +396,11 @@ func testAccPreCheckOkmsCredential(t *testing.T) { | |
checkEnvOrSkip(t, "OVH_OKMS_CREDENTIAL") | ||
} | ||
|
||
func testAccPreCheckVrack(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed, there is already the |
||
testAccPreCheckCredentials(t) | ||
checkEnvOrSkip(t, "OVH_VRACK_SERVICE_TEST") | ||
} | ||
|
||
func testAccCheckVRackExists(t *testing.T) { | ||
type vrackResponse struct { | ||
Name string `json:"name"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.