Skip to content

Commit 6870db0

Browse files
committed
feat(omni): add support for GCP imagePullServiceAccount
1 parent da4fcba commit 6870db0

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

castai/resource_edge_location.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type awsModel struct {
6666

6767
type gcpModel struct {
6868
ProjectID types.String `tfsdk:"project_id"`
69+
InstanceServiceAccount types.String `tfsdk:"instance_service_account"`
6970
ClientServiceAccountJSONBase64WO types.String `tfsdk:"client_service_account_json_base64_wo"`
7071
NetworkName types.String `tfsdk:"network_name"`
7172
SubnetName types.String `tfsdk:"subnet_name"`
@@ -108,7 +109,8 @@ func (m gcpModel) Equal(other *gcpModel) bool {
108109
return m.ProjectID.Equal(other.ProjectID) &&
109110
m.NetworkName.Equal(other.NetworkName) &&
110111
m.SubnetName.Equal(other.SubnetName) &&
111-
m.NetworkTags.Equal(other.NetworkTags)
112+
m.NetworkTags.Equal(other.NetworkTags) &&
113+
m.InstanceServiceAccount.Equal(other.InstanceServiceAccount)
112114
}
113115

114116
func (m ociModel) credentials() types.String {
@@ -260,6 +262,10 @@ func (r *edgeLocationResource) Schema(_ context.Context, _ resource.SchemaReques
260262
Required: true,
261263
Description: "GCP project ID where edges run",
262264
},
265+
"instance_service_account": schema.StringAttribute{
266+
Optional: true,
267+
Description: "GCP service account email to be attached to edge instances. It can be used to grant permissions to access other GCP resources.",
268+
},
263269
"client_service_account_json_base64_wo": schema.StringAttribute{
264270
Required: true,
265271
Sensitive: true,
@@ -736,8 +742,14 @@ func (r *edgeLocationResource) toGCP(ctx context.Context, plan, config *gcpModel
736742
return nil, diags
737743
}
738744

745+
var instanceServiceAccount *string
746+
if !plan.InstanceServiceAccount.IsNull() && plan.InstanceServiceAccount.ValueString() != "" {
747+
instanceServiceAccount = lo.ToPtr(plan.InstanceServiceAccount.ValueString())
748+
}
749+
739750
out := &omni.GCPParam{
740-
ProjectId: plan.ProjectID.ValueString(),
751+
ProjectId: plan.ProjectID.ValueString(),
752+
InstanceServiceAccount: instanceServiceAccount,
741753
Credentials: &omni.GCPParamCredentials{
742754
ClientServiceAccountJsonBase64: config.ClientServiceAccountJSONBase64WO.ValueString(),
743755
},
@@ -759,12 +771,17 @@ func (r *edgeLocationResource) toGCPModel(ctx context.Context, config *omni.GCPP
759771

760772
gcp := &gcpModel{
761773
ProjectID: types.StringValue(config.ProjectId),
774+
InstanceServiceAccount: types.StringNull(),
762775
ClientServiceAccountJSONBase64WO: types.StringNull(),
763776
NetworkName: types.StringNull(),
764777
SubnetName: types.StringNull(),
765778
NetworkTags: types.SetNull(types.StringType),
766779
}
767780

781+
if config.InstanceServiceAccount != nil {
782+
gcp.InstanceServiceAccount = types.StringValue(*config.InstanceServiceAccount)
783+
}
784+
768785
if config.Networking != nil {
769786
gcp.NetworkName = types.StringValue(config.Networking.NetworkName)
770787
gcp.SubnetName = types.StringValue(config.Networking.SubnetName)

castai/resource_edge_location_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TestAccCloudAgnostic_ResourceEdgeLocationGCP(t *testing.T) {
101101
resource.TestCheckResourceAttr(resourceName, "zones.1.id", "us-central1-b"),
102102
resource.TestCheckResourceAttr(resourceName, "zones.1.name", "us-central1-b"),
103103
resource.TestCheckResourceAttrSet(resourceName, "gcp.project_id"),
104+
resource.TestCheckResourceAttr(resourceName, "gcp.instance_service_account", "custom-sa@test-project-123456.iam.gserviceaccount.com"),
104105
resource.TestCheckResourceAttrSet(resourceName, "id"),
105106
resource.TestCheckResourceAttr(resourceName, "credentials_revision", "1"),
106107
),
@@ -302,11 +303,12 @@ resource "castai_edge_location" "test" {
302303
%[3]s
303304
304305
gcp = {
305-
project_id = "test-project-123456"
306+
project_id = "test-project-123456"
307+
instance_service_account = "custom-sa@test-project-123456.iam.gserviceaccount.com"
306308
%[5]s
307-
network_name = "test-network"
308-
subnet_name = "test-subnet"
309-
network_tags = [%[4]s]
309+
network_name = "test-network"
310+
subnet_name = "test-subnet"
311+
network_tags = [%[4]s]
310312
}
311313
}
312314
`, rName, description, zonesConfig, networkTagsConfig, gcpCredentials, organizationID))

docs/resources/edge_location.md

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

0 commit comments

Comments
 (0)