Skip to content

Commit

Permalink
Add support for using trusted lauch on Azure images
Browse files Browse the repository at this point in the history
  • Loading branch information
sternik committed Jul 5, 2024
1 parent 4521c84 commit ddf197a
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ terraform {
required_providers {
imagefactory = {
source = "nordcloud/imagefactory"
version = "1.8.5"
version = "1.9.1"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ Optional:
- `eol_date_option` (Boolean) Default value is set to true
- `exclude_from_latest` (Boolean)
- `replica_regions` (List of String)
- `trusted_launch` (Boolean)
- `vm_image_definition` (Block List) (see [below for nested schema](#nestedblock--config--azure--vm_image_definition))

<a id="nestedblock--config--azure--additional_data_disks"></a>
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ terraform {
required_providers {
imagefactory = {
source = "nordcloud/imagefactory"
version = "1.8.5"
version = "1.9.1"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions imagefactory/distribution/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func distributionRead(ctx context.Context, d *schema.ResourceData, m interface{}
return diag.FromErr(err)
}

if distro.Deprecated != nil && *distro.Deprecated {
return diag.Errorf("Distribution %s is deprecated. Use another distribution.", distro.Name)
}

d.SetId(string(distro.ID))
if err := d.Set("name", distro.Name); err != nil {
return diag.FromErr(err)
Expand Down
4 changes: 4 additions & 0 deletions imagefactory/imagetemplate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func resourceTemplateUpdate(ctx context.Context, d *schema.ResourceData, m inter
templateID := d.Id()
name := graphql.String(d.Get("name").(string))

if d.HasChange("distribution_id") {
return diag.Errorf("Changing distribution is not possible. Create a new template using the new distribution.")
}

tplCfg, err := expandTemplateConfig(d.Get("config").([]interface{}))
if err != nil {
return diag.FromErr(err)
Expand Down
4 changes: 4 additions & 0 deletions imagefactory/imagetemplate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ var azureTemplateConfigResource = &schema.Resource{
Elem: additionalDataDisksResource,
MaxItems: 10,
},
"trusted_launch": {
Type: schema.TypeBool,
Optional: true,
},
},
}

Expand Down
3 changes: 2 additions & 1 deletion imagefactory/imagetemplate/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func expandTemplateAzureConfig(in []interface{}) *graphql.NewTemplateAZUREConfig
m := in[0].(map[string]interface{})

e := graphql.Boolean(m["exclude_from_latest"].(bool))

eol := graphql.Boolean(m["eol_date_option"].(bool))
tl := graphql.Boolean(m["trusted_launch"].(bool))

rr := []graphql.String{}
for _, v := range m["replica_regions"].([]interface{}) {
Expand All @@ -141,6 +141,7 @@ func expandTemplateAzureConfig(in []interface{}) *graphql.NewTemplateAZUREConfig
ExcludeFromLatest: &e,
EolDateOption: &eol,
ReplicaRegions: &rr,
TrustedLaunch: &tl,
VmImageDefinition: expandVMImageDefinitionTemplateAzureConfig(m["vm_image_definition"].([]interface{})),
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/graphql/distribution.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Nordcloud Oy or its affiliates. All Rights Reserved.
# Copyright 2021-2024 Nordcloud Oy or its affiliates. All Rights Reserved.

query GetDistributions($input: DistributionsInput!) {
distributions(input: $input) {
Expand All @@ -7,6 +7,7 @@ query GetDistributions($input: DistributionsInput!) {
name
description
provider
deprecated
}
}
}
6 changes: 6 additions & 0 deletions pkg/graphql/graphql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ type TemplateAZUREConfig {
vmImageDefinition: VMImageDefinition
eolDateOption: Boolean
additionalDataDisks: [AdditionalDataDisks!]
trustedLaunch: Boolean
}

type TemplateExoscaleConfig {
Expand All @@ -1029,6 +1030,7 @@ type TemplateConfig {
notifications: [Notification!]
scope: Scope
disableCyclicalRebuilds: Boolean
imageRetainCount: Int
aws: TemplateAWSConfig
azure: TemplateAZUREConfig
exoscale: TemplateExoscaleConfig
Expand Down Expand Up @@ -1161,6 +1163,15 @@ input NewTemplateAZUREConfig {
vmImageDefinition: NewVMImageDefinition
eolDateOption: Boolean

"""
`trustedLaunch` defines if the image is trusted launch enabled.
Trusted launch is a feature that helps protect virtual machines from threats that can compromise the boot process.
This feature is only available for new templates and cannot be changed after the template is created.
This feature is only available for Gen2 VMs.
"""
trustedLaunch: Boolean

"""
`additionalDataDisks` defines extra data disks attached to the image with a limit of 10.
Expand Down Expand Up @@ -1224,6 +1235,16 @@ input NewTemplateConfig {
the template will not be rebuilt automatically and the user will have to trigger the rebuild manually.
"""
disableCyclicalRebuilds: Boolean

"""
imageRetainCount defines the number of images to retain on the customer's cloud account.
This feature allows ImageFactory to automatically remove the oldest image from the customer's cloud account when
a new image is distributed, if the number of images exceeds the specified `imageRetainCount`. To allow this operation,
ImageFactory requires the necessary permissions to remove images from the customer's cloud account.
By default, ImageFactory does not remove any images from the customer's cloud account.
"""
imageRetainCount: Int
}

input NewTemplate {
Expand Down

0 comments on commit ddf197a

Please sign in to comment.