From b5e848a87e5eac9f3b32fd0ce63e4911ff8b93cd Mon Sep 17 00:00:00 2001 From: Malte Poll <1780588+malt3@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:27:12 +0100 Subject: [PATCH] terraform: provide required configuration for yawol on OpenStack --- cli/internal/terraform/terraform.go | 12 ++++++++ internal/constellation/helm/overrides.go | 2 ++ internal/constellation/state/state.go | 10 +++++++ internal/constellation/state/state_doc.go | 29 ++++++++++++++++++- terraform/infrastructure/openstack/outputs.tf | 7 +++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/cli/internal/terraform/terraform.go b/cli/internal/terraform/terraform.go index 58ce818e1..374170ecc 100644 --- a/cli/internal/terraform/terraform.go +++ b/cli/internal/terraform/terraform.go @@ -340,6 +340,18 @@ func (c *Client) ShowInfrastructure(ctx context.Context, provider cloudprovider. LoadBalancerName: loadBalancerName, AttestationURL: attestationURL, } + case cloudprovider.OpenStack: + networkIDOutput, ok := tfState.Values.Outputs["network_id"] + if !ok { + return state.Infrastructure{}, errors.New("no network_id output found") + } + networkID, ok := networkIDOutput.Value.(string) + if !ok { + return state.Infrastructure{}, errors.New("invalid type in network_id output: not a string") + } + res.OpenStack = &state.OpenStack{ + NetworkID: networkID, + } } return res, nil } diff --git a/internal/constellation/helm/overrides.go b/internal/constellation/helm/overrides.go index 2b075516a..48e25c1ec 100644 --- a/internal/constellation/helm/overrides.go +++ b/internal/constellation/helm/overrides.go @@ -125,6 +125,8 @@ func extraConstellationServicesValues( "yawolFloatingID": openStackCfg.FloatingIPPoolID, "yawolFlavorID": openStackCfg.YawolFlavorID, "yawolImageID": openStackCfg.YawolImageID, + "yawolNetworkID": output.OpenStack.NetworkID, + "yawolAPIHost": fmt.Sprintf("https://%s:%d", output.InClusterEndpoint, constants.KubernetesPort), } } case cloudprovider.GCP: diff --git a/internal/constellation/state/state.go b/internal/constellation/state/state.go index 4ebc11f4f..80610c596 100644 --- a/internal/constellation/state/state.go +++ b/internal/constellation/state/state.go @@ -132,6 +132,9 @@ type Infrastructure struct { // description: | // Values specific to a Constellation cluster running on GCP. GCP *GCP `yaml:"gcp,omitempty"` + // description: | + // Values specific to a Constellation cluster running on OpenStack. + OpenStack *OpenStack `yaml:"openstack,omitempty"` } // GCP describes the infra state related to GCP. @@ -168,6 +171,13 @@ type Azure struct { AttestationURL string `yaml:"attestationURL"` } +// OpenStack describes the infra state related to OpenStack. +type OpenStack struct { + // description: | + // ID of the network + NetworkID string `yaml:"networkID"` +} + // New creates a new cluster state (file). func New() *State { return &State{ diff --git a/internal/constellation/state/state_doc.go b/internal/constellation/state/state_doc.go index 7666c26d9..230bdb698 100644 --- a/internal/constellation/state/state_doc.go +++ b/internal/constellation/state/state_doc.go @@ -16,6 +16,7 @@ var ( InfrastructureDoc encoder.Doc GCPDoc encoder.Doc AzureDoc encoder.Doc + OpenStackDoc encoder.Doc ) func init() { @@ -74,7 +75,7 @@ func init() { FieldName: "infrastructure", }, } - InfrastructureDoc.Fields = make([]encoder.Doc, 9) + InfrastructureDoc.Fields = make([]encoder.Doc, 10) InfrastructureDoc.Fields[0].Name = "uid" InfrastructureDoc.Fields[0].Type = "string" InfrastructureDoc.Fields[0].Note = "" @@ -120,6 +121,11 @@ func init() { InfrastructureDoc.Fields[8].Note = "" InfrastructureDoc.Fields[8].Description = "Values specific to a Constellation cluster running on GCP." InfrastructureDoc.Fields[8].Comments[encoder.LineComment] = "Values specific to a Constellation cluster running on GCP." + InfrastructureDoc.Fields[9].Name = "openstack" + InfrastructureDoc.Fields[9].Type = "OpenStack" + InfrastructureDoc.Fields[9].Note = "" + InfrastructureDoc.Fields[9].Description = "Values specific to a Constellation cluster running on OpenStack." + InfrastructureDoc.Fields[9].Comments[encoder.LineComment] = "Values specific to a Constellation cluster running on OpenStack." GCPDoc.Type = "GCP" GCPDoc.Comments[encoder.LineComment] = "GCP describes the infra state related to GCP." @@ -182,6 +188,22 @@ func init() { AzureDoc.Fields[5].Note = "" AzureDoc.Fields[5].Description = "MAA endpoint that can be used as a fallback for veryifying the ID key digests\nin the cluster's attestation report if the enforcement policy is set accordingly.\nCan be left empty otherwise." AzureDoc.Fields[5].Comments[encoder.LineComment] = "MAA endpoint that can be used as a fallback for veryifying the ID key digests" + + OpenStackDoc.Type = "OpenStack" + OpenStackDoc.Comments[encoder.LineComment] = "OpenStack describes the infra state related to OpenStack." + OpenStackDoc.Description = "OpenStack describes the infra state related to OpenStack." + OpenStackDoc.AppearsIn = []encoder.Appearance{ + { + TypeName: "Infrastructure", + FieldName: "openstack", + }, + } + OpenStackDoc.Fields = make([]encoder.Doc, 1) + OpenStackDoc.Fields[0].Name = "networkID" + OpenStackDoc.Fields[0].Type = "string" + OpenStackDoc.Fields[0].Note = "" + OpenStackDoc.Fields[0].Description = "ID of the network" + OpenStackDoc.Fields[0].Comments[encoder.LineComment] = "ID of the network" } func (_ State) Doc() *encoder.Doc { @@ -204,6 +226,10 @@ func (_ Azure) Doc() *encoder.Doc { return &AzureDoc } +func (_ OpenStack) Doc() *encoder.Doc { + return &OpenStackDoc +} + // GetConfigurationDoc returns documentation for the file ./state_doc.go. func GetConfigurationDoc() *encoder.FileDoc { return &encoder.FileDoc{ @@ -215,6 +241,7 @@ func GetConfigurationDoc() *encoder.FileDoc { &InfrastructureDoc, &GCPDoc, &AzureDoc, + &OpenStackDoc, }, } } diff --git a/terraform/infrastructure/openstack/outputs.tf b/terraform/infrastructure/openstack/outputs.tf index 34b84a61e..35a85fe50 100644 --- a/terraform/infrastructure/openstack/outputs.tf +++ b/terraform/infrastructure/openstack/outputs.tf @@ -35,3 +35,10 @@ output "ip_cidr_node" { value = local.cidr_vpc_subnet_nodes description = "CIDR block of the node network." } + +# OpenStack-specific outputs + +output "network_id" { + value = openstack_networking_network_v2.vpc_network.id + description = "The OpenStack network id the cluster is deployed in." +}