Skip to content

Commit

Permalink
Update the target stable Ignition spec version to v3.4.0
Browse files Browse the repository at this point in the history
* Upstream Ignition has stabalized the v3.4.0 spec and can parse
and merge earlier versions to v3.4.0 (Ignition forward compatibility)
* Convert fcos variant Butane Configs to Ignition v3.4.0 spec
* Convert flatcar variant Butane Configs to Ignition v3.4.0 spec
  • Loading branch information
dghubble committed Apr 1, 2023
1 parent d037237 commit 46692ea
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Notable changes between releases.

## Latest

* Update the target stable Ignition spec version to v3.4.0 ([#156](https://github.com/poseidon/terraform-provider-ct/pull/156))
* Parse Butane Configs to Ignition v3.4.0

## v0.12.0

* Remove support for Container Linux Configs ([#132](https://github.com/poseidon/terraform-provider-ct/pull/132))
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ SEMVER=$(shell git describe --tags --match=v* --always --dirty | cut -c 2-)
all: build test vet fmt

.PHONY: build
build: clean bin/terraform-provider-ct

bin/terraform-provider-ct:
build:
@go build -o $@ github.com/poseidon/terraform-provider-ct

.PHONY: test
Expand All @@ -24,6 +22,10 @@ vet:
fmt:
@test -z $$(go fmt ./...)

.PHONY: lint
lint:
@golangci-lint run ./...

.PHONY: clean
clean:
@rm -rf bin
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ $ terraform init

## Versions

Butane configs are converted to the current (according to this provider) stable Ignition config and merged together. For example, a Butane Config with `version: 1.2.0` would produce an Ignition config with version `v3.3.0`. This relies on Ignition's [forward compatibility](https://github.com/coreos/ignition/blob/main/config/v3_3/config.go#L61).
Butane configs are converted to the current (according to this provider) stable Ignition config and merged together. For example, `poseidon/ct` `v0.12.0` would convert a Butane Config with `variant: fcos` and `version: 1.2.0` to an Ignition config with version `v3.3.0`. This relies on Ignition's [forward compatibility](https://github.com/coreos/ignition/blob/main/config/v3_3/config.go#L61).

| terraform-provider-ct | Butane variant | Butane version | Ignition verison |
| poseidon/ct | Butane variant | Butane version | Ignition verison |
|-----------------------|----------------|----------------|------------------|
| 0.13.x | fcos | 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0 | 3.4.0 |
| 0.13.x | flatcar | 1.0.0, 1.1.0 | 3.4.0 |
| 0.12.x | fcos | 1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0 | 3.3.0 |
| 0.12.x | flatcar | 1.0.0 | 3.3.0 |

Expand Down
8 changes: 4 additions & 4 deletions ct/datasource_ct_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

butane "github.com/coreos/butane/config"
"github.com/coreos/butane/config/common"
ignition33 "github.com/coreos/ignition/v2/config/v3_3"
ignition "github.com/coreos/ignition/v2/config/v3_4"
)

func dataSourceCTConfig() *schema.Resource {
Expand Down Expand Up @@ -110,7 +110,7 @@ func butaneToIgnition(data []byte, pretty, strict bool, snippets []string) ([]by

// Parse Fedora CoreOS Ignition and Butane snippets into Ignition Config.
func mergeFCCSnippets(ignBytes []byte, pretty, strict bool, snippets []string) ([]byte, error) {
ign, _, err := ignition33.ParseCompatibleVersion(ignBytes)
ign, _, err := ignition.ParseCompatibleVersion(ignBytes)
if err != nil {
return nil, fmt.Errorf("%v", err)
}
Expand All @@ -130,11 +130,11 @@ func mergeFCCSnippets(ignBytes []byte, pretty, strict bool, snippets []string) (
return nil, fmt.Errorf("strict parsing error: %v", report.String())
}

ignext, _, err := ignition33.ParseCompatibleVersion(ignextBytes)
ignext, _, err := ignition.ParseCompatibleVersion(ignextBytes)
if err != nil {
return nil, fmt.Errorf("snippet parse error: %v, expect v1.4.0", err)
}
ign = ignition33.Merge(ign, ignext)
ign = ignition.Merge(ign, ignext)
}

return marshalJSON(ign, pretty)
Expand Down
127 changes: 117 additions & 10 deletions ct/datasource_ct_config_flatcar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,114 @@ import (
r "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const flatcarResource = `
// Flatcar variant, v1.1.0

const flatcarV11Resource = `
data "ct_config" "flatcar" {
pretty_print = true
strict = true
content = <<EOT
---
variant: flatcar
version: 1.1.0
storage:
luks:
- name: data
device: /dev/vdb
passwd:
users:
- name: core
ssh_authorized_keys:
- key
EOT
}
`

const flatcarV11WithSnippets = `
data "ct_config" "flatcar-snippets" {
pretty_print = true
strict = true
content = <<EOT
---
variant: flatcar
version: 1.1.0
passwd:
users:
- name: core
ssh_authorized_keys:
- key
EOT
snippets = [
<<EOT
---
variant: flatcar
version: 1.1.0
systemd:
units:
- name: docker.service
enabled: true
EOT
]
}
`

const flatcarV11WithSnippetsPrettyFalse = `
data "ct_config" "flatcar-snippets" {
pretty_print = false
strict = true
content = <<EOT
---
variant: flatcar
version: 1.1.0
passwd:
users:
- name: core
ssh_authorized_keys:
- key
EOT
snippets = [
<<EOT
---
variant: flatcar
version: 1.1.0
systemd:
units:
- name: docker.service
enabled: true
EOT
]
}
`

func TestButaneConfig_Flatcar_v1_1(t *testing.T) {
r.UnitTest(t, r.TestCase{
Providers: testProviders,
Steps: []r.TestStep{
{
Config: flatcarV11Resource,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar", "rendered", flatcarExpected),
),
},
{
Config: flatcarV11WithSnippets,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar-snippets", "rendered", flatcarWithSnippetsExpected),
),
},
{
Config: flatcarV11WithSnippetsPrettyFalse,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar-snippets", "rendered", flatcarWithSnippetsPrettyFalseExpected),
),
},
},
})
}

// Flatcar variant, v1.0.0

const flatcarV10Resource = `
data "ct_config" "flatcar" {
pretty_print = true
strict = true
Expand Down Expand Up @@ -39,7 +146,7 @@ const flatcarExpected = `{
"tls": {}
},
"timeouts": {},
"version": "3.3.0"
"version": "3.4.0"
},
"kernelArguments": {},
"passwd": {
Expand Down Expand Up @@ -69,7 +176,7 @@ const flatcarExpected = `{
"systemd": {}
}`

const flatcarWithSnippets = `
const flatcarV10WithSnippets = `
data "ct_config" "flatcar-snippets" {
pretty_print = true
strict = true
Expand Down Expand Up @@ -109,7 +216,7 @@ const flatcarWithSnippetsExpected = `{
"tls": {}
},
"timeouts": {},
"version": "3.3.0"
"version": "3.4.0"
},
"kernelArguments": {},
"passwd": {
Expand All @@ -133,7 +240,7 @@ const flatcarWithSnippetsExpected = `{
}
}`

const flatcarWithSnippetsPrettyFalse = `
const flatcarV10WithSnippetsPrettyFalse = `
data "ct_config" "flatcar-snippets" {
pretty_print = false
strict = true
Expand Down Expand Up @@ -161,26 +268,26 @@ EOT
}
`

const flatcarWithSnippetsPrettyFalseExpected = `{"ignition":{"config":{"replace":{"verification":{}}},"proxy":{},"security":{"tls":{}},"timeouts":{},"version":"3.3.0"},"kernelArguments":{},"passwd":{"users":[{"name":"core","sshAuthorizedKeys":["key"]}]},"storage":{},"systemd":{"units":[{"enabled":true,"name":"docker.service"}]}}`
const flatcarWithSnippetsPrettyFalseExpected = `{"ignition":{"config":{"replace":{"verification":{}}},"proxy":{},"security":{"tls":{}},"timeouts":{},"version":"3.4.0"},"kernelArguments":{},"passwd":{"users":[{"name":"core","sshAuthorizedKeys":["key"]}]},"storage":{},"systemd":{"units":[{"enabled":true,"name":"docker.service"}]}}`

func TestFlatcarButaneConfig(t *testing.T) {
func TestButaneConfig_Flatcar_v1_0(t *testing.T) {
r.UnitTest(t, r.TestCase{
Providers: testProviders,
Steps: []r.TestStep{
{
Config: flatcarResource,
Config: flatcarV10Resource,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar", "rendered", flatcarExpected),
),
},
{
Config: flatcarWithSnippets,
Config: flatcarV10WithSnippets,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar-snippets", "rendered", flatcarWithSnippetsExpected),
),
},
{
Config: flatcarWithSnippetsPrettyFalse,
Config: flatcarV10WithSnippetsPrettyFalse,
Check: r.ComposeTestCheckFunc(
r.TestCheckResourceAttr("data.ct_config.flatcar-snippets", "rendered", flatcarWithSnippetsPrettyFalseExpected),
),
Expand Down

0 comments on commit 46692ea

Please sign in to comment.