Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 44d829b

Browse files
committed
config: pass VM service account from iam create to cluster create via config
1 parent dbe7f50 commit 44d829b

16 files changed

Lines changed: 76 additions & 51 deletions

File tree

cli/internal/cloudcmd/tfvars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func gcpTerraformVars(conf *config.Config, imageRef string) *terraform.GCPCluste
231231
InternalLoadBalancer: conf.InternalLoadBalancer,
232232
CCTechnology: ccTech,
233233
AdditionalLabels: conf.Tags,
234+
IAMServiceAccountVM: conf.Provider.GCP.IAMServiceAccountVM,
234235
}
235236
}
236237

cli/internal/cmd/apply_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func TestValidateInputs(t *testing.T) {
256256
ClientX509CertURL: "client_cert",
257257
}))
258258
cfg.Provider.GCP.ServiceAccountKeyPath = "saKey.json"
259+
cfg.Provider.GCP.IAMServiceAccountVM = "example@example.com"
259260
}
260261

261262
require.NoError(fh.WriteYAML(constants.ConfigFilename, cfg))

cli/internal/cmd/iamcreategcp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ func (c *gcpIAMCreator) printOutputValues(cmd *cobra.Command, _ cloudcmd.IAMOutp
145145
cmd.Printf("serviceAccountKeyPath:\t%s\n\n", c.flags.pathPrefixer.PrefixPrintablePath(constants.GCPServiceAccountKeyFilename))
146146
}
147147

148-
func (c *gcpIAMCreator) writeOutputValuesToConfig(conf *config.Config, _ cloudcmd.IAMOutput) {
148+
func (c *gcpIAMCreator) writeOutputValuesToConfig(conf *config.Config, out cloudcmd.IAMOutput) {
149149
conf.Provider.GCP.Project = c.flags.projectID
150150
conf.Provider.GCP.ServiceAccountKeyPath = constants.GCPServiceAccountKeyFilename // File was created in workspace, so only the filename is needed.
151151
conf.Provider.GCP.Region = c.flags.region
152152
conf.Provider.GCP.Zone = c.flags.zone
153+
conf.Provider.GCP.IAMServiceAccountVM = out.GCPOutput.IAMServiceAccountVM
153154
for groupName, group := range conf.NodeGroups {
154155
group.Zone = c.flags.zone
155156
conf.NodeGroups[groupName] = group

cli/internal/cmd/init_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ func defaultConfigWithExpectedMeasurements(t *testing.T, conf *config.Config, cs
539539
conf.Provider.GCP.Project = "test-project"
540540
conf.Provider.GCP.Zone = "test-zone"
541541
conf.Provider.GCP.ServiceAccountKeyPath = "test-key-path"
542+
conf.Provider.GCP.IAMServiceAccountVM = "example@example.com"
542543
conf.Attestation.GCPSEVSNP.Measurements[4] = measurements.WithAllBytes(0x44, measurements.Enforce, measurements.PCRMeasurementLength)
543544
conf.Attestation.GCPSEVSNP.Measurements[9] = measurements.WithAllBytes(0x11, measurements.Enforce, measurements.PCRMeasurementLength)
544545
conf.Attestation.GCPSEVSNP.Measurements[12] = measurements.WithAllBytes(0xcc, measurements.Enforce, measurements.PCRMeasurementLength)

cli/internal/terraform/variables.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ type GCPClusterVariables struct {
141141
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
142142
// CCTechnology is the confidential computing technology to use on the VMs. (`SEV` or `SEV_SNP`)
143143
CCTechnology string `hcl:"cc_technology" cty:"cc_technology"`
144+
// IAMServiceAccountControlPlane is the IAM service account mail address to attach to VMs.
145+
IAMServiceAccountVM string `hcl:"iam_service_account_vm" cty:"iam_service_account_vm"`
144146
// AdditionalLables are (optional) additional labels that should be applied to created resources.
145147
AdditionalLabels cloudprovider.Tags `hcl:"additional_labels" cty:"additional_labels"`
146148
}

cli/internal/terraform/variables_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ func TestGCPClusterVariables(t *testing.T) {
122122
DiskType: "pd-ssd",
123123
},
124124
},
125-
CustomEndpoint: "example.com",
126-
CCTechnology: "SEV_SNP",
125+
CustomEndpoint: "example.com",
126+
CCTechnology: "SEV_SNP",
127+
IAMServiceAccountVM: "example@example.com",
127128
}
128129

129130
// test that the variables are correctly rendered
@@ -151,10 +152,11 @@ node_groups = {
151152
zone = "eu-central-1b"
152153
}
153154
}
154-
custom_endpoint = "example.com"
155-
internal_load_balancer = false
156-
cc_technology = "SEV_SNP"
157-
additional_labels = null
155+
custom_endpoint = "example.com"
156+
internal_load_balancer = false
157+
cc_technology = "SEV_SNP"
158+
iam_service_account_vm = "example@example.com"
159+
additional_labels = null
158160
`
159161
got := vars.String()
160162
assert.Equal(t, strings.Fields(want), strings.Fields(got)) // to ignore whitespace differences

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ type GCPConfig struct {
188188
// Path of service account key file. For required service account roles, see https://docs.edgeless.systems/constellation/getting-started/install#authorization
189189
ServiceAccountKeyPath string `yaml:"serviceAccountKeyPath" validate:"required"`
190190
// description: |
191+
// GCP service account mail address. This is being attached to the VMs for authorization.
192+
IAMServiceAccountVM string `yaml:"IAMServiceAccountVM"`
193+
// description: |
191194
// Deploy Persistent Disk CSI driver with on-node encryption. For details see: https://docs.edgeless.systems/constellation/architecture/encrypted-storage
192195
DeployCSIDriver *bool `yaml:"deployCSIDriver" validate:"required"`
193196
// description: |
@@ -349,6 +352,7 @@ func Default() *Config {
349352
Region: "",
350353
Zone: "",
351354
ServiceAccountKeyPath: "",
355+
IAMServiceAccountVM: "",
352356
DeployCSIDriver: toPtr(true),
353357
UseMarketplaceImage: toPtr(false),
354358
},

internal/config/config_doc.go

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/config/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ func TestValidate(t *testing.T) {
464464
gcp.Project = "test-project"
465465
gcp.Zone = "test-zone"
466466
gcp.ServiceAccountKeyPath = "test-key-path"
467+
gcp.IAMServiceAccountVM = "example@example.com"
467468
cnf.Provider = ProviderConfig{}
468469
cnf.Provider.GCP = gcp
469470
cnf.Attestation.GCPSEVSNP.Measurements = measurements.M{

terraform-provider-constellation/examples/full/gcp/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ module "gcp_infrastructure" {
8181
project = local.project_id
8282
internal_load_balancer = false
8383
cc_technology = local.cc_technology
84+
iam_service_account_vm = module.gcp_iam.service_account_mail_vm
8485
}
8586

8687
data "constellation_attestation" "foo" {

0 commit comments

Comments
 (0)