Merge pull request #11327 from hashicorp/b-fix-ignition-systemd-units
provider/ignition: Fix systemd unit errors
This commit is contained in:
commit
ca21fd0141
|
@ -83,7 +83,7 @@ func testIgnition(t *testing.T, input string, assert func(*types.Config) error)
|
|||
resource.Test(t, resource.TestCase{
|
||||
Providers: testProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
{
|
||||
Config: fmt.Sprintf(testTemplate, input),
|
||||
Check: check,
|
||||
},
|
||||
|
|
|
@ -12,39 +12,39 @@ func resourceSystemdUnit() *schema.Resource {
|
|||
Exists: resourceSystemdUnitExists,
|
||||
Read: resourceSystemdUnitRead,
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"enable": &schema.Schema{
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"mask": &schema.Schema{
|
||||
"mask": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"content": &schema.Schema{
|
||||
"content": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"dropin": &schema.Schema{
|
||||
"dropin": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"content": &schema.Schema{
|
||||
"content": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
|
@ -100,7 +100,7 @@ func buildSystemdUnit(d *schema.ResourceData, c *cache) (string, error) {
|
|||
}
|
||||
|
||||
if err := validateUnitContent(d.Get("content").(string)); err != nil {
|
||||
if err != errEmptyUnit || (err == errEmptyUnit && len(dropins) == 0) {
|
||||
if err != errEmptyUnit {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,3 +94,35 @@ func TestIngnitionSystemdUnitEmptyContentWithDropIn(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// #11325
|
||||
func TestIgnitionSystemdUnit_emptyContent(t *testing.T) {
|
||||
testIgnition(t, `
|
||||
resource "ignition_systemd_unit" "foo" {
|
||||
name = "foo.service"
|
||||
enable = true
|
||||
}
|
||||
|
||||
resource "ignition_config" "test" {
|
||||
systemd = [
|
||||
"${ignition_systemd_unit.foo.id}",
|
||||
]
|
||||
}
|
||||
`, func(c *types.Config) error {
|
||||
if len(c.Systemd.Units) != 1 {
|
||||
return fmt.Errorf("systemd, found %d", len(c.Systemd.Units))
|
||||
}
|
||||
|
||||
u := c.Systemd.Units[0]
|
||||
if u.Name != "foo.service" {
|
||||
return fmt.Errorf("name, expected 'foo.service', found %q", u.Name)
|
||||
}
|
||||
if u.Contents != "" {
|
||||
return fmt.Errorf("expected empty content, found %q", u.Contents)
|
||||
}
|
||||
if len(u.DropIns) != 0 {
|
||||
return fmt.Errorf("expected 0 dropins, found %q", u.DropIns)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue