-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/243-ip-ranges-cannot-detect-changes
- Loading branch information
Showing
21 changed files
with
676 additions
and
69 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "maas_boot_source_selection Data Source - terraform-provider-maas" | ||
subcategory: "" | ||
description: |- | ||
Provides a resource to fetch a MAAS boot source selection. | ||
--- | ||
|
||
# maas_boot_source_selection (Data Source) | ||
|
||
Provides a resource to fetch a MAAS boot source selection. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "maas_boot_source" "default" {} | ||
data "maas_boot_source_selection" "default" { | ||
boot_source = data.maas_boot_source.default.id | ||
os = "ubuntu" | ||
release = "noble" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `boot_source` (Number) The boot source database ID this resource is associated with. | ||
- `os` (String) The operating system for this selection. | ||
- `release` (String) The specific release of the operating system for this selection. | ||
|
||
### Read-Only | ||
|
||
- `arches` (Set of String) The architecture list for this selection. | ||
- `id` (String) The ID of this resource. | ||
- `labels` (Set of String) The label list for this selection. | ||
- `subarches` (Set of String) The list of subarches for this selection. |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "maas_boot_source_selection Resource - terraform-provider-maas" | ||
subcategory: "" | ||
description: |- | ||
Provides a resource to manage a MAAS boot source selection. | ||
--- | ||
|
||
# maas_boot_source_selection (Resource) | ||
|
||
Provides a resource to manage a MAAS boot source selection. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "maas_boot_source" "test_boot_source" { | ||
url = "http://images.maas.io/ephemeral-v3/candidate/" | ||
} | ||
resource "maas_boot_source_selection" "test" { | ||
boot_source = maas_boot_source.test_boot_source.id | ||
os = "ubuntu" | ||
release = "jammy" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `boot_source` (Number) The boot source database ID this selection is associated with. | ||
- `os` (String) The operating system for this selection. | ||
- `release` (String) The specific release of the operating system for this selection. | ||
|
||
### Optional | ||
|
||
- `arches` (Set of String) The architecture list for this selection. | ||
- `labels` (Set of String) The label list for this selection. | ||
- `subarches` (Set of String) The list of subarches for this selection. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# A boot resource selection can be imported using the boot source ID and the boot source selection ID. e.g. | ||
$ terraform import maas_boot_source.example boot_source:id | ||
``` |
8 changes: 8 additions & 0 deletions
8
examples/data-sources/maas_boot_source_selection/data-source.tf
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
data "maas_boot_source" "default" {} | ||
|
||
data "maas_boot_source_selection" "default" { | ||
boot_source = data.maas_boot_source.default.id | ||
|
||
os = "ubuntu" | ||
release = "noble" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# A boot resource selection can be imported using the boot source ID and the boot source selection ID. e.g. | ||
$ terraform import maas_boot_source.example boot_source:id |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "maas_boot_source" "test_boot_source" { | ||
url = "http://images.maas.io/ephemeral-v3/candidate/" | ||
} | ||
|
||
resource "maas_boot_source_selection" "test" { | ||
boot_source = maas_boot_source.test_boot_source.id | ||
|
||
os = "ubuntu" | ||
release = "jammy" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package maas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/canonical/gomaasclient/client" | ||
"github.com/canonical/gomaasclient/entity" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceMaasBootSourceSelection() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMaasBootSourceSelectionRead, | ||
Description: "Provides a resource to fetch a MAAS boot source selection.", | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arches": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
Description: "The architecture list for this selection.", | ||
}, | ||
"boot_source": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "The boot source database ID this resource is associated with.", | ||
}, | ||
"labels": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
Description: "The label list for this selection.", | ||
}, | ||
"os": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The operating system for this selection.", | ||
}, | ||
"release": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The specific release of the operating system for this selection.", | ||
}, | ||
"subarches": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
Description: "The list of subarches for this selection.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMaasBootSourceSelectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*ClientConfig).Client | ||
|
||
bootsourceselection, err := getBootSourceSelectionByRelease(client, d.Get("boot_source").(int), d.Get("os").(string), d.Get("release").(string)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(fmt.Sprintf("%v", bootsourceselection.ID)) | ||
|
||
tfState := map[string]interface{}{ | ||
"arches": bootsourceselection.Arches, | ||
"boot_source": bootsourceselection.BootSourceID, | ||
"labels": bootsourceselection.Labels, | ||
"os": bootsourceselection.OS, | ||
"release": bootsourceselection.Release, | ||
"subarches": bootsourceselection.Subarches, | ||
} | ||
if err := setTerraformState(d, tfState); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getBootSourceSelectionByRelease(client *client.Client, boot_source int, os string, release string) (*entity.BootSourceSelection, error) { | ||
bootsourceselection, err := findBootSourceSelection(client, boot_source, os, release) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if bootsourceselection == nil { | ||
return nil, fmt.Errorf("boot source selection (%s %s) was not found", os, release) | ||
} | ||
return bootsourceselection, nil | ||
} | ||
|
||
func findBootSourceSelection(client *client.Client, boot_source int, os string, release string) (*entity.BootSourceSelection, error) { | ||
bootsourceselections, err := client.BootSourceSelections.Get(boot_source) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, d := range bootsourceselections { | ||
if d.OS == os && d.Release == release { | ||
return &d, nil | ||
} | ||
} | ||
return nil, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package maas_test | ||
|
||
import ( | ||
"fmt" | ||
"terraform-provider-maas/maas/testutils" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceMaasBootSourceSelection_basic(t *testing.T) { | ||
os := "ubuntu" | ||
release := "mantic" | ||
arches := []string{"amd64"} | ||
subarches := []string{"*"} | ||
labels := []string{"*"} | ||
|
||
checks := []resource.TestCheckFunc{ | ||
resource.TestCheckResourceAttrSet("data.maas_boot_source_selection.test", "boot_source"), | ||
resource.TestCheckResourceAttr("data.maas_boot_source_selection.test", "os", os), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "release", release), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "arches.#", "1"), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "arches.0", arches[0]), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "subarches.#", "1"), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "subarches.0", subarches[0]), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "labels.#", "1"), | ||
resource.TestCheckResourceAttr("maas_boot_source_selection.test", "labels.0", labels[0]), | ||
} | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testutils.PreCheck(t, nil) }, | ||
Providers: testutils.TestAccProviders, | ||
CheckDestroy: testAccCheckMAASBootSourceSelectionDestroy, | ||
ErrorCheck: func(err error) error { return err }, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMaasBootSourceSelection(os, release, arches, subarches, labels), | ||
Check: resource.ComposeTestCheckFunc(checks...), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceMaasBootSourceSelection(os string, release string, arches []string, subarches []string, labels []string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "maas_boot_source_selection" "test" { | ||
boot_source = maas_boot_source_selection.test.boot_source | ||
os = maas_boot_source_selection.test.os | ||
release = maas_boot_source_selection.test.release | ||
} | ||
`, testAccMAASBootSourceSelection(os, release, arches, subarches, labels)) | ||
} |
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
Oops, something went wrong.