diff --git a/docs/index.md b/docs/index.md index 0f457d2..569aefa 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,7 @@ terraform { required_providers { imagefactory = { source = "nordcloud/imagefactory" - version = "1.8.5" + version = "1.9.1" } } } diff --git a/docs/resources/template.md b/docs/resources/template.md index fa4abc9..ad12247 100644 --- a/docs/resources/template.md +++ b/docs/resources/template.md @@ -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)) diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index a5bbd96..417b591 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -7,7 +7,7 @@ terraform { required_providers { imagefactory = { source = "nordcloud/imagefactory" - version = "1.8.5" + version = "1.9.1" } } } diff --git a/imagefactory/distribution/data_source.go b/imagefactory/distribution/data_source.go index 0930b53..0d990d0 100644 --- a/imagefactory/distribution/data_source.go +++ b/imagefactory/distribution/data_source.go @@ -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) diff --git a/imagefactory/imagetemplate/resource.go b/imagefactory/imagetemplate/resource.go index 9ccadae..16c081e 100644 --- a/imagefactory/imagetemplate/resource.go +++ b/imagefactory/imagetemplate/resource.go @@ -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) diff --git a/imagefactory/imagetemplate/schema.go b/imagefactory/imagetemplate/schema.go index 902118f..f698e40 100644 --- a/imagefactory/imagetemplate/schema.go +++ b/imagefactory/imagetemplate/schema.go @@ -158,6 +158,10 @@ var azureTemplateConfigResource = &schema.Resource{ Elem: additionalDataDisksResource, MaxItems: 10, }, + "trusted_launch": { + Type: schema.TypeBool, + Optional: true, + }, }, } diff --git a/imagefactory/imagetemplate/structures.go b/imagefactory/imagetemplate/structures.go index 4f9987e..8fc3bcc 100644 --- a/imagefactory/imagetemplate/structures.go +++ b/imagefactory/imagetemplate/structures.go @@ -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{}) { @@ -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{})), } diff --git a/pkg/graphql/distribution.graphql b/pkg/graphql/distribution.graphql index 5477717..e5dc33b 100644 --- a/pkg/graphql/distribution.graphql +++ b/pkg/graphql/distribution.graphql @@ -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) { @@ -7,6 +7,7 @@ query GetDistributions($input: DistributionsInput!) { name description provider + deprecated } } } diff --git a/pkg/graphql/graphql.go b/pkg/graphql/graphql.go index cecbb9e..bbd231e 100644 --- a/pkg/graphql/graphql.go +++ b/pkg/graphql/graphql.go @@ -1417,6 +1417,7 @@ type GetDistributionsResponse struct { Name string `json:"name"` Description string `json:"description"` Provider string `json:"provider"` + Deprecated string `json:"deprecated"` } `json:"results"` } `json:"distributions"` } @@ -1439,6 +1440,7 @@ func NewGetDistributionsRequest(url string, vars *GetDistributionsVariables) (*G name description provider + deprecated } } }`, @@ -3678,6 +3680,7 @@ type NewTemplateAZUREConfig struct { EolDateOption *Boolean `json:"eolDateOption,omitempty"` ExcludeFromLatest *Boolean `json:"excludeFromLatest,omitempty"` ReplicaRegions *[]String `json:"replicaRegions,omitempty"` + TrustedLaunch *Boolean `json:"trustedLaunch,omitempty"` VmImageDefinition *NewVMImageDefinition `json:"vmImageDefinition,omitempty"` } @@ -3699,6 +3702,7 @@ type NewTemplateConfig struct { CloudAccountIds *[]String `json:"cloudAccountIds,omitempty"` DisableCyclicalRebuilds *Boolean `json:"disableCyclicalRebuilds,omitempty"` Exoscale *NewTemplateExoscaleConfig `json:"exoscale,omitempty"` + ImageRetainCount *Int `json:"imageRetainCount,omitempty"` Notifications *[]NewNotification `json:"notifications,omitempty"` Scope *Scope `json:"scope,omitempty"` Tags *[]NewTag `json:"tags,omitempty"` @@ -4262,6 +4266,7 @@ type TemplateAZUREConfig struct { EolDateOption *Boolean `json:"eolDateOption,omitempty"` ExcludeFromLatest *Boolean `json:"excludeFromLatest,omitempty"` ReplicaRegions *[]String `json:"replicaRegions,omitempty"` + TrustedLaunch *Boolean `json:"trustedLaunch,omitempty"` VmImageDefinition *VMImageDefinition `json:"vmImageDefinition,omitempty"` } @@ -4284,6 +4289,7 @@ type TemplateConfig struct { CloudAccountIds *[]String `json:"cloudAccountIds,omitempty"` DisableCyclicalRebuilds *Boolean `json:"disableCyclicalRebuilds,omitempty"` Exoscale *TemplateExoscaleConfig `json:"exoscale,omitempty"` + ImageRetainCount *Int `json:"imageRetainCount,omitempty"` Notifications *[]Notification `json:"notifications,omitempty"` Scope *Scope `json:"scope,omitempty"` Tags *[]Tag `json:"tags,omitempty"` diff --git a/pkg/graphql/schema.graphql b/pkg/graphql/schema.graphql index 4b0875a..c07776b 100644 --- a/pkg/graphql/schema.graphql +++ b/pkg/graphql/schema.graphql @@ -1016,6 +1016,7 @@ type TemplateAZUREConfig { vmImageDefinition: VMImageDefinition eolDateOption: Boolean additionalDataDisks: [AdditionalDataDisks!] + trustedLaunch: Boolean } type TemplateExoscaleConfig { @@ -1029,6 +1030,7 @@ type TemplateConfig { notifications: [Notification!] scope: Scope disableCyclicalRebuilds: Boolean + imageRetainCount: Int aws: TemplateAWSConfig azure: TemplateAZUREConfig exoscale: TemplateExoscaleConfig @@ -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. @@ -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 {