provider/ignition: Fix systemd unit errors
According to the coreos [documentation](https://coreos.com/ignition/docs/latest/configuration.html), systemd units only require the name attribute per each unit. This can also be validated with the CoreOS config validator. This change allows the `ignition_systemd_unit` resource to no longer fail if given an empty `content` and `dropin`. Also adds a test to cover this use case.
This commit is contained in:
parent
02b3fd289a
commit
f458feb055
|
@ -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