-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from cobbler/feature/upgrade-tf-sdk-v2
Update Terraform SDK to v2
- Loading branch information
Showing
24 changed files
with
562 additions
and
955 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,55 +8,58 @@ on: | |
- 'v*' | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
|
||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: '1.17' | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/[email protected] | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
sudo apt-get install -y xorriso | ||
- name: Build | ||
run: | | ||
go build -v . | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
id: go | ||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
sudo apt-get install -y xorriso | ||
- name: Build | ||
run: | | ||
go build -v . | ||
unit: | ||
name: Unit Tests | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: 'go.mod' | ||
- run: go test -v -cover ./... | ||
test: | ||
name: Testing | ||
name: Integration Tests | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: '1.17' | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/[email protected] | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: Make Test | ||
run: | | ||
make testacc | ||
- name: Make Vet | ||
run: | | ||
make vet | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
id: go | ||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: Make Test | ||
run: | | ||
make testacc | ||
- name: Make Vet | ||
run: | | ||
make vet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ terraform-provider-cobbler | |
debug | ||
dist/ | ||
vendor/ | ||
docker/cobbler_source/ | ||
extracted_iso_image/ | ||
*.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,27 @@ | ||
run: | ||
deadline: 5m | ||
# Visit https://golangci-lint.run/ for usage documentation | ||
# and information on other useful linters | ||
issues: | ||
max-per-linter: 0 | ||
max-same-issues: 0 | ||
|
||
linters: | ||
fast: false | ||
disable-all: true | ||
enable: | ||
- asciicheck | ||
- bodyclose | ||
- deadcode | ||
- depguard | ||
- dogsled | ||
- exhaustive | ||
- durationcheck | ||
- errcheck | ||
- exportloopref | ||
- forcetypeassert | ||
- godot | ||
- gofmt | ||
- goheader | ||
- goimports | ||
- golint | ||
- govet | ||
- gosimple | ||
- ineffassign | ||
- makezero | ||
- misspell | ||
- nakedret | ||
- nolintlint | ||
- rowserrcheck | ||
- nilerr | ||
- predeclared | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- tenv | ||
- unconvert | ||
- unparam | ||
- unused | ||
- varcheck | ||
- whitespace | ||
|
||
service: | ||
golangci-lint-version: 1.32.x # use the fixed version to not introduce new linters unexpectedly | ||
- govet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,79 @@ | ||
package cobbler | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
"context" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// Provider does the talking to the Cobbler API. | ||
func Provider() terraform.ResourceProvider { | ||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"url": { | ||
Description: "The url to the Cobbler service. This can also be specified with the `COBBLER_URL` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_URL", nil), | ||
}, | ||
func New(version string) func() *schema.Provider { | ||
return func() *schema.Provider { | ||
p := &schema.Provider{ | ||
Schema: map[string]*schema.Schema{ | ||
"url": { | ||
Description: "The url to the Cobbler service. This can also be specified with the `COBBLER_URL` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_URL", nil), | ||
}, | ||
|
||
"username": { | ||
Description: "The username to the Cobbler service. This can also be specified with the `COBBLER_USERNAME` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_USERNAME", nil), | ||
}, | ||
"username": { | ||
Description: "The username to the Cobbler service. This can also be specified with the `COBBLER_USERNAME` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_USERNAME", nil), | ||
}, | ||
|
||
"password": { | ||
Description: "The password to the Cobbler service. This can also be specified with the `COBBLER_PASSWORD` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_PASSWORD", nil), | ||
}, | ||
"password": { | ||
Description: "The password to the Cobbler service. This can also be specified with the `COBBLER_PASSWORD` shell environment variable.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_PASSWORD", nil), | ||
}, | ||
|
||
"insecure": { | ||
Description: "The url to the Cobbler service. This can also be specified with the `COBBLER_URL` shell environment variable.", | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_INSECURE", nil), | ||
}, | ||
"insecure": { | ||
Description: "The url to the Cobbler service. This can also be specified with the `COBBLER_URL` shell environment variable.", | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_INSECURE", nil), | ||
}, | ||
|
||
"cacert_file": { | ||
Description: "The path or contents of an SSL CA certificate. This can also be specified with the `COBBLER_CACERT_FILE`shell environment variable.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_CACERT_FILE", nil), | ||
"cacert_file": { | ||
Description: "The path or contents of an SSL CA certificate. This can also be specified with the `COBBLER_CACERT_FILE`shell environment variable.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
DefaultFunc: schema.EnvDefaultFunc("COBBLER_CACERT_FILE", nil), | ||
}, | ||
}, | ||
}, | ||
|
||
ResourcesMap: map[string]*schema.Resource{ | ||
"cobbler_distro": resourceDistro(), | ||
"cobbler_template_file": resourceTemplateFile(), | ||
"cobbler_profile": resourceProfile(), | ||
"cobbler_repo": resourceRepo(), | ||
"cobbler_snippet": resourceSnippet(), | ||
"cobbler_system": resourceSystem(), | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"cobbler_distro": resourceDistro(), | ||
"cobbler_template_file": resourceTemplateFile(), | ||
"cobbler_profile": resourceProfile(), | ||
"cobbler_repo": resourceRepo(), | ||
"cobbler_snippet": resourceSnippet(), | ||
"cobbler_system": resourceSystem(), | ||
}, | ||
} | ||
p.ConfigureContextFunc = configure(version, p) | ||
|
||
ConfigureFunc: configureProvider, | ||
return p | ||
} | ||
} | ||
|
||
func configureProvider(d *schema.ResourceData) (interface{}, error) { | ||
config := Config{ | ||
CACertFile: d.Get("cacert_file").(string), | ||
Insecure: d.Get("insecure").(bool), | ||
URL: d.Get("url").(string), | ||
Username: d.Get("username").(string), | ||
Password: d.Get("password").(string), | ||
} | ||
func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { | ||
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { | ||
config := Config{ | ||
CACertFile: d.Get("cacert_file").(string), | ||
Insecure: d.Get("insecure").(bool), | ||
URL: d.Get("url").(string), | ||
Username: d.Get("username").(string), | ||
Password: d.Get("password").(string), | ||
} | ||
|
||
if err := config.loadAndValidate(); err != nil { | ||
return nil, err | ||
} | ||
if err := config.loadAndValidate(); err != nil { | ||
return nil, diag.FromErr(err) | ||
} | ||
|
||
return &config, nil | ||
return &config, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.