Skip to content
Snippets Groups Projects
Unverified Commit b7b6bcb8 authored by Andrew Reed's avatar Andrew Reed
Browse files

More tests

parent ed8baed5
No related branches found
No related tags found
No related merge requests found
...@@ -116,7 +116,20 @@ func fromAPI(ctx context.Context, device *v20250101.Device, state utils.Attribut ...@@ -116,7 +116,20 @@ func fromAPI(ctx context.Context, device *v20250101.Device, state utils.Attribut
diags.Append(d...) diags.Append(d...)
model.Metadata = metadata model.Metadata = metadata
} else { } else {
model.Metadata = types.MapNull(types.StringType) // see comment in utils/optional.go
metadataFromState := types.Map{}
d := state.GetAttribute(ctx, path.Root("metadata"), &metadataFromState)
diags.Append(d...)
switch {
case metadataFromState.IsUnknown():
model.Metadata = types.MapNull(types.StringType)
case metadataFromState.IsNull():
model.Metadata = metadataFromState
case len(metadataFromState.Elements()) == 0:
model.Metadata = metadataFromState
default:
model.Metadata = types.MapNull(types.StringType)
}
} }
if device.ApprovedAt != nil { if device.ApprovedAt != nil {
...@@ -173,7 +186,9 @@ func toAPI(ctx context.Context, m *Model) (*v20250101.DeviceRequest, diag.Diagno ...@@ -173,7 +186,9 @@ func toAPI(ctx context.Context, m *Model) (*v20250101.DeviceRequest, diag.Diagno
Value: v.ValueString(), Value: v.ValueString(),
}) })
} }
d.Metadata = &metadata if len(metadata) > 0 {
d.Metadata = &metadata
}
} }
if !m.Tags.IsNull() && !m.Tags.IsUnknown() { if !m.Tags.IsNull() && !m.Tags.IsUnknown() {
var tags []string var tags []string
......
...@@ -6,12 +6,15 @@ import ( ...@@ -6,12 +6,15 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
v20250101 "github.com/smallstep/terraform-provider-smallstep/internal/apiclient/v20250101" v20250101 "github.com/smallstep/terraform-provider-smallstep/internal/apiclient/v20250101"
"github.com/smallstep/terraform-provider-smallstep/internal/provider/utils" "github.com/smallstep/terraform-provider-smallstep/internal/provider/utils"
) )
...@@ -26,6 +29,59 @@ type Resource struct { ...@@ -26,6 +29,59 @@ type Resource struct {
client *v20250101.Client client *v20250101.Client
} }
func (r *Resource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
if req.Plan.Raw.IsNull() {
// Delete
return
}
// Attributes that may either be set by API or synced from an MDM are marked as
// optional and computed. When one of these attributes is removed from the
// config the plan keeps the old value instead of setting it to null. We have
// to modify the plan and change the attribute to null.
optionalComputedStrings := []path.Path{
path.Root("display_id"),
path.Root("display_name"),
path.Root("serial"),
path.Root("os"),
path.Root("ownership"),
}
for _, p := range optionalComputedStrings {
config := types.String{}
diags := req.Config.GetAttribute(ctx, p, &config)
resp.Diagnostics.Append(diags...)
if !config.IsNull() {
continue
}
resp.Plan.SetAttribute(ctx, p, config)
}
email := types.String{}
diags := req.Config.GetAttribute(ctx, path.Root("user").AtName("email"), &email)
resp.Diagnostics.Append(diags...)
if email.IsNull() {
user := basetypes.NewObjectNull(userAttrTypes)
diags = resp.Plan.SetAttribute(ctx, path.Root("user"), user)
resp.Diagnostics.Append(diags...)
}
tags := types.Set{}
diags = req.Config.GetAttribute(ctx, path.Root("tags"), &tags)
resp.Diagnostics.Append(diags...)
if tags.IsNull() {
diags = resp.Plan.SetAttribute(ctx, path.Root("tags"), tags)
resp.Diagnostics.Append(diags...)
}
metadata := types.Map{}
diags = req.Config.GetAttribute(ctx, path.Root("metadata"), &metadata)
resp.Diagnostics.Append(diags...)
if metadata.IsNull() || len(metadata.Elements()) == 0 {
diags = resp.Plan.SetAttribute(ctx, path.Root("metadata"), metadata)
resp.Diagnostics.Append(diags...)
}
}
func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
device, props, err := utils.Describe("device") device, props, err := utils.Describe("device")
if err != nil { if err != nil {
...@@ -61,7 +117,7 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp ...@@ -61,7 +117,7 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
Required: true, Required: true,
}, },
"serial": schema.StringAttribute{ "serial": schema.StringAttribute{
MarkdownDescription: props["permanent_identifier"], MarkdownDescription: props["serial"],
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
...@@ -110,6 +166,9 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp ...@@ -110,6 +166,9 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
"email": schema.StringAttribute{ "email": schema.StringAttribute{
MarkdownDescription: userProps["email"], MarkdownDescription: userProps["email"],
Required: true, Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 256),
},
}, },
}, },
}, },
...@@ -337,6 +396,10 @@ func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp ...@@ -337,6 +396,10 @@ func (r *Resource) Update(ctx context.Context, req resource.UpdateRequest, resp
patch.UserEmail = &resource.User.Email patch.UserEmail = &resource.User.Email
} }
if len(remove) > 0 {
patch.Remove = &remove
}
httpResp, err := r.client.PatchDevice(ctx, deviceID, &v20250101.PatchDeviceParams{}, patch) httpResp, err := r.client.PatchDevice(ctx, deviceID, &v20250101.PatchDeviceParams{}, patch)
if err != nil { if err != nil {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
......
...@@ -28,24 +28,63 @@ var providerFactories = map[string]func() (tfprotov6.ProviderServer, error){ ...@@ -28,24 +28,63 @@ var providerFactories = map[string]func() (tfprotov6.ProviderServer, error){
"smallstep": providerserver.NewProtocol6WithError(provider), "smallstep": providerserver.NewProtocol6WithError(provider),
} }
func TestAccAuthorityResource(t *testing.T) { const minConfig = `
t.Parallel() resource "smallstep_device" "laptop1" {
permanent_identifier = %q
}`
permanentID := uuid.NewString() const maxConfig = `
resource "smallstep_device" "laptop1" {
permanent_identifier = %q
display_id = "9 9"
display_name = "Employee Laptop"
serial = "678"
tags = ["ubuntu"]
metadata = {
k1 = "v1"
}
os = "Windows"
ownership = "company"
user = {
email = "user@example.com"
}
}`
emptyConfig := fmt.Sprintf(` const emptyConfig = `
resource "smallstep_device" "laptop1" { resource "smallstep_device" "laptop1" {
permanent_identifier = %q permanent_identifier = %q
}`, permanentID) display_id = ""
display_name = ""
serial = ""
tags = []
metadata = {}
}
`
func TestAccDeviceResource(t *testing.T) {
permanentID := uuid.NewString()
// min -> max
helper.Test(t, helper.TestCase{ helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories, ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{ Steps: []helper.TestStep{
{ {
Config: emptyConfig, Config: fmt.Sprintf(minConfig, permanentID),
Check: helper.ComposeAggregateTestCheckFunc( Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)), helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID), helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_id"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_name"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "serial"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "metadata"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "tags"),
), ),
}, },
{ {
...@@ -53,32 +92,66 @@ resource "smallstep_device" "laptop1" { ...@@ -53,32 +92,66 @@ resource "smallstep_device" "laptop1" {
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },
{
Config: fmt.Sprintf(maxConfig, permanentID),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_id", "9 9"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_name", "Employee Laptop"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "serial", "678"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "user.email", "user@example.com"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "os", "Windows"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "ownership", "company"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "tags.0", "ubuntu"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "metadata.k1", "v1"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
),
},
},
})
// min -> empty
permanentID1 := uuid.NewString()
helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{
{
Config: fmt.Sprintf(minConfig, permanentID1),
},
{
Config: fmt.Sprintf(emptyConfig, permanentID1),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID1),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_id", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_name", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "serial", ""),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "metadata.%", "0"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "tags.%", "0"),
),
},
}, },
}) })
permanentID2 := uuid.NewString() permanentID2 := uuid.NewString()
fullConfig := fmt.Sprintf(`
resource "smallstep_device" "laptop1" {
permanent_identifier = %q
display_id = "9 9"
display_name = "Employee Laptop"
serial = "678"
tags = ["ubuntu"]
metadata = {
k1 = "v1"
}
os = "Windows"
ownership = "company"
user = {
email = "user@example.com"
}
}`, permanentID2)
// max -> min
helper.Test(t, helper.TestCase{ helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories, ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{ Steps: []helper.TestStep{
{ {
Config: fullConfig, Config: fmt.Sprintf(maxConfig, permanentID2),
Check: helper.ComposeAggregateTestCheckFunc( Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)), helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID2), helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID2),
...@@ -101,39 +174,34 @@ resource "smallstep_device" "laptop1" { ...@@ -101,39 +174,34 @@ resource "smallstep_device" "laptop1" {
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },
{
Config: fmt.Sprintf(minConfig, permanentID2),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID2),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_id"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_name"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "serial"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user.email"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "metadata"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "tags"),
),
},
}, },
}) })
permanentID3 := uuid.NewString() permanentID3 := uuid.NewString()
config1 := fmt.Sprintf(`
resource "smallstep_device" "laptop1" {
permanent_identifier = %q
}`, permanentID3)
config2 := fmt.Sprintf(`
resource "smallstep_device" "laptop1" {
permanent_identifier = %q
display_id = "9 9"
display_name = "Employee Laptop"
serial = "678"
tags = ["ubuntu"]
metadata = {
k1 = "v1"
}
os = "Windows"
ownership = "company"
user = {
email = "user@example.com"
}
}`, permanentID3)
// max -> empty
helper.Test(t, helper.TestCase{ helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories, ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{ Steps: []helper.TestStep{
{ {
Config: config1, Config: fmt.Sprintf(maxConfig, permanentID3),
},
{
Config: config2,
Check: helper.ComposeAggregateTestCheckFunc( Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)), helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID3), helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID3),
...@@ -156,6 +224,109 @@ resource "smallstep_device" "laptop1" { ...@@ -156,6 +224,109 @@ resource "smallstep_device" "laptop1" {
ImportState: true, ImportState: true,
ImportStateVerify: true, ImportStateVerify: true,
}, },
{
Config: fmt.Sprintf(emptyConfig, permanentID3),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID3),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_id", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_name", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "serial", ""),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "metadata.%", "0"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "tags.%", "0"),
),
},
},
})
permanentID4 := uuid.NewString()
// empty -> min
helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{
{
Config: fmt.Sprintf(emptyConfig, permanentID4),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID4),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_id", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_name", ""),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "serial", ""),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "metadata.%", "0"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "tags.%", "0"),
),
},
{
ResourceName: "smallstep_device.laptop1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"display_id", "display_name", "serial"},
},
{
Config: fmt.Sprintf(minConfig, permanentID4),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID4),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_id"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "display_name"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "serial"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "user"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "os"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "ownership"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "metadata"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "tags"),
),
},
},
})
// empty -> max
permanentID5 := uuid.NewString()
helper.Test(t, helper.TestCase{
ProtoV6ProviderFactories: providerFactories,
Steps: []helper.TestStep{
{
Config: fmt.Sprintf(emptyConfig, permanentID5),
},
{
Config: fmt.Sprintf(maxConfig, permanentID5),
Check: helper.ComposeAggregateTestCheckFunc(
helper.TestMatchResourceAttr("smallstep_device.laptop1", "id", regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "permanent_identifier", permanentID5),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_id", "9 9"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "display_name", "Employee Laptop"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "serial", "678"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "user.email", "user@example.com"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "os", "Windows"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "ownership", "company"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "tags.0", "ubuntu"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "metadata.k1", "v1"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "connected", "false"),
helper.TestCheckResourceAttr("smallstep_device.laptop1", "high_assurance", "false"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "enrolled_at"),
helper.TestCheckNoResourceAttr("smallstep_device.laptop1", "last_seen"),
),
},
}, },
}) })
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment