Skip to content

Commit 45e6145

Browse files
committed
feat: add InstanceProfile support for AWS edge location
1 parent 70aab6f commit 45e6145

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

castai/resource_edge_location.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type zoneModel struct {
5656

5757
type awsModel struct {
5858
AccountID types.String `tfsdk:"account_id"`
59+
InstanceProfile types.String `tfsdk:"instance_profile"`
5960
AccessKeyIDWO types.String `tfsdk:"access_key_id_wo"`
6061
SecretAccessKeyWO types.String `tfsdk:"secret_access_key_wo"`
6162
VpcID types.String `tfsdk:"vpc_id"`
@@ -97,7 +98,8 @@ func (m awsModel) Equal(other *awsModel) bool {
9798
m.VpcID.Equal(other.VpcID) &&
9899
m.VpcPeered.Equal(other.VpcPeered) &&
99100
m.SecurityGroupID.Equal(other.SecurityGroupID) &&
100-
m.SubnetIDs.Equal(other.SubnetIDs)
101+
m.SubnetIDs.Equal(other.SubnetIDs) &&
102+
m.InstanceProfile.Equal(other.InstanceProfile)
101103
}
102104

103105
func (m gcpModel) credentials() types.String {
@@ -225,6 +227,10 @@ func (r *edgeLocationResource) Schema(_ context.Context, _ resource.SchemaReques
225227
Required: true,
226228
Description: "AWS account ID",
227229
},
230+
"instance_profile": schema.StringAttribute{
231+
Optional: true,
232+
Description: "AWS IAM instance profile ARN to be attached to edge instances. It can be used to grant permissions to access other AWS resources such as ECR.",
233+
},
228234
"access_key_id_wo": schema.StringAttribute{
229235
Required: true,
230236
WriteOnly: true,
@@ -688,8 +694,14 @@ func (r *edgeLocationResource) toAWS(ctx context.Context, plan, config *awsModel
688694
return nil, diags
689695
}
690696

697+
var instanceProfile *string
698+
if !plan.InstanceProfile.IsNull() && plan.InstanceProfile.ValueString() != "" {
699+
instanceProfile = lo.ToPtr(plan.InstanceProfile.ValueString())
700+
}
701+
691702
out := &omni.AWSParam{
692-
AccountId: toPtr(plan.AccountID.ValueString()),
703+
AccountId: toPtr(plan.AccountID.ValueString()),
704+
InstanceProfile: instanceProfile,
693705
Credentials: &omni.AWSParamCredentials{
694706
AccessKeyId: config.AccessKeyIDWO.ValueString(),
695707
SecretAccessKey: config.SecretAccessKeyWO.ValueString(),
@@ -716,6 +728,7 @@ func (r *edgeLocationResource) toAWSModel(ctx context.Context, config *omni.AWSP
716728

717729
aws := &awsModel{
718730
AccountID: types.StringValue(lo.FromPtr(config.AccountId)),
731+
InstanceProfile: types.StringNull(),
719732
VpcID: types.StringNull(),
720733
SecurityGroupID: types.StringNull(),
721734
VpcPeered: types.BoolNull(),
@@ -725,6 +738,10 @@ func (r *edgeLocationResource) toAWSModel(ctx context.Context, config *omni.AWSP
725738
SecretAccessKeyWO: types.StringNull(),
726739
}
727740

741+
if config.InstanceProfile != nil && *config.InstanceProfile != "" {
742+
aws.InstanceProfile = types.StringValue(*config.InstanceProfile)
743+
}
744+
728745
if config.Networking != nil {
729746
aws.VpcID = types.StringValue(config.Networking.VpcId)
730747
aws.VpcPeered = types.BoolPointerValue(config.Networking.VpcPeered)

castai/resource_edge_location_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestAccCloudAgnostic_ResourceEdgeLocationAWS(t *testing.T) {
3434
resource.TestCheckResourceAttr(resourceName, "zones.1.id", "us-east-1b"),
3535
resource.TestCheckResourceAttr(resourceName, "zones.1.name", "us-east-1b"),
3636
resource.TestCheckResourceAttrSet(resourceName, "aws.account_id"),
37+
resource.TestCheckResourceAttr(resourceName, "aws.instance_profile", "arn:aws:iam::123456789012:instance-profile/edge-node-profile"),
3738
resource.TestCheckResourceAttrSet(resourceName, "aws.vpc_id"),
3839
resource.TestCheckResourceAttrSet(resourceName, "aws.vpc_peered"),
3940
resource.TestCheckResourceAttrSet(resourceName, "aws.security_group_id"),
@@ -216,6 +217,7 @@ resource "castai_edge_location" "test" {
216217
217218
aws = {
218219
account_id = "123456789012"
220+
instance_profile = "arn:aws:iam::123456789012:instance-profile/edge-node-profile"
219221
%[6]s
220222
vpc_id = "vpc-12345678"
221223
vpc_peered = true

docs/resources/edge_location.md

Lines changed: 1 addition & 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)