Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions docs/data-sources/machine_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_machine_types Data Source - stackit"
subcategory: ""
description: |-
Lists all available machine types in a project and region. Results are sorted by name.
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_machine_types (Data Source)

Lists all available machine types in a project and region. Results are sorted by name.

~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.

## Example Usage

```terraform
# List all available machine types in the provider region.
data "stackit_machine_types" "all" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

# Match exactly 1 vCPU and 1024 MB of RAM. All filters are combined with AND.
data "stackit_machine_types" "small" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
filter = {
vcpu = 1
ram = 1024
}
}

# Filter by extra specs in an explicitly selected region.
data "stackit_machine_types" "intel" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region = "eu01"
filter = {
vcpu = 2
extra_specs = {
cpu = "intel-icelake-generic"
}
}
}

output "small_machine_types" {
value = data.stackit_machine_types.small.results
}

# Use HCL for more complex filtering, such as a minimum RAM size.
output "high_memory_machine_types" {
value = [
for machine_type in data.stackit_machine_types.all.results : machine_type
if machine_type.ram >= 4096
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) STACKIT project ID.

### Optional

- `filter` (Attributes) Experimental API-side equality filters, which may be subject to breaking changes. All configured attributes and extra spec entries are combined with AND. Omit this object or use an empty object to list all machine types. (see [below for nested schema](#nestedatt--filter))
- `region` (String) Region override. Uses the provider region when omitted.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) Stable Terraform ID, structured as "`project_id`,`region`".
- `results` (Attributes List) All matching machine types, sorted by name ascending. Empty if no machine types match. (see [below for nested schema](#nestedatt--results))

<a id="nestedatt--filter"></a>
### Nested Schema for `filter`

Optional:

- `disk` (Number) Exact disk size in GB to match.
- `extra_specs` (Map of String) Extra specs to match by key and exact value (e.g., cpu or overcommit).
- `name` (String) Exact machine type name to match.
- `ram` (Number) Exact RAM size in MB to match.
- `vcpu` (Number) Exact number of vCPUs to match.


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).


<a id="nestedatt--results"></a>
### Nested Schema for `results`

Read-Only:

- `description` (String) Machine type description.
- `disk` (Number) Disk size in GB.
- `extra_specs` (Map of String) Extra specs (e.g., CPU type or overcommit ratio).
- `name` (String) Machine type name.
- `ram` (Number) RAM size in MB.
- `vcpus` (Number) Number of vCPUs.
37 changes: 37 additions & 0 deletions examples/data-sources/stackit_machine_types/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# List all available machine types in the provider region.
data "stackit_machine_types" "all" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

# Match exactly 1 vCPU and 1024 MB of RAM. All filters are combined with AND.
data "stackit_machine_types" "small" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
filter = {
vcpu = 1
ram = 1024
}
}

# Filter by extra specs in an explicitly selected region.
data "stackit_machine_types" "intel" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region = "eu01"
filter = {
vcpu = 2
extra_specs = {
cpu = "intel-icelake-generic"
}
}
}

output "small_machine_types" {
value = data.stackit_machine_types.small.results
}

# Use HCL for more complex filtering, such as a minimum RAM size.
output "high_memory_machine_types" {
value = [
for machine_type in data.stackit_machine_types.all.results : machine_type
if machine_type.ram >= 4096
]
}
30 changes: 30 additions & 0 deletions stackit/internal/services/iaas/iaas_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ var (
//go:embed testdata/datasource-machinetype.tf
dataSourceMachineTypeConfig string

//go:embed testdata/datasource-machine-types.tf
dataSourceMachineTypesConfig string

//go:embed testdata/resource-routingtable-min.tf
resourceRoutingTableMinConfig string

Expand Down Expand Up @@ -5205,6 +5208,33 @@ func TestAccProject(t *testing.T) {
})
}

func TestAccMachineTypesDatasource(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{{
ConfigVariables: config.Variables{
"project_id": config.StringVariable(testutil.ProjectId),
},
Config: fmt.Sprintf("%s\n%s", dataSourceMachineTypesConfig, testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.stackit_machine_types.all", "id", testutil.ProjectId+","+testutil.Region),
resource.TestCheckResourceAttr("data.stackit_machine_types.all", "region", testutil.Region),
resource.TestCheckResourceAttrSet("data.stackit_machine_types.all", "results.0.name"),
resource.TestCheckResourceAttrSet("data.stackit_machine_types.all", "results.0.vcpus"),
resource.TestCheckResourceAttrSet("data.stackit_machine_types.all", "results.0.ram"),
resource.TestCheckResourceAttr("data.stackit_machine_types.exact", "results.#", "1"),
resource.TestCheckResourceAttr("data.stackit_machine_types.no_match", "results.#", "0"),
resource.TestCheckResourceAttr("data.stackit_machine_types.no_match", "region", testutil.Region),
resource.TestCheckResourceAttr("data.stackit_machine_types.no_match", "id", testutil.ProjectId+","+testutil.Region),
resource.TestCheckOutput("machine_types_sorted", "true"),
resource.TestCheckOutput("machine_types_empty_filter_matches_all", "true"),
resource.TestCheckOutput("machine_types_hardware_matches", "true"),
resource.TestCheckOutput("machine_types_exact_matches", "true"),
),
}},
})
}

func TestAccMachineType(t *testing.T) {
t.Logf("TestAccMachineType projectid: %s", testutil.ConvertConfigVariable(testConfigMachineTypeVars["project_id"]))
resource.ParallelTest(t, resource.TestCase{
Expand Down
Loading
Loading