Skip to content

Commit

Permalink
Handle num_replicas field coming from api when not set in the .tf file (
Browse files Browse the repository at this point in the history
  • Loading branch information
whites11 authored Oct 24, 2024
1 parent c238ba7 commit ee5b4b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,10 @@ jobs:
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
- name: Mark error
id: status
if: always()
if: failure()
run: |
if [ "${{ steps.e2e.outcome }}" == "success" ]
then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
exit 1
fi
echo "status=failure" >> $GITHUB_OUTPUT
exit 1
report:
runs-on: ubuntu-latest
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,10 @@ jobs:

- name: Mark error
id: status
if: always()
if: failure()
run: |
if [ "${{ steps.e2e.outcome }}" == "success" ]
then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
exit 1
fi
echo "status=failure" >> $GITHUB_OUTPUT
exit 1
report:
runs-on: ubuntu-latest
Expand Down
29 changes: 26 additions & 3 deletions pkg/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ func (r *ServiceResource) Schema(_ context.Context, _ resource.SchemaRequest, re
Optional: true,
},
"num_replicas": schema.Int64Attribute{
Description: "Number of replicas for the service. Available only for 'production' services. Must be between 3 and 20. Contact support to enable this feature.",
Optional: true,
Computed: true,
Description: "Number of replicas for the service. Available only for 'production' services. Must be between 3 and 20. Contact support to enable this feature.",
},
"idle_timeout_minutes": schema.Int64Attribute{
Description: "Set minimum idling timeout (in minutes). Must be greater than or equal to 5 minutes. Must be set if idle_scaling is enabled",
Expand Down Expand Up @@ -344,10 +345,24 @@ func (r *ServiceResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
}

if plan.Tier.ValueString() == api.TierDevelopment {
if !plan.MinTotalMemoryGb.IsNull() || !plan.MaxTotalMemoryGb.IsNull() || !plan.NumReplicas.IsNull() {
if !plan.MinTotalMemoryGb.IsNull() {
resp.Diagnostics.AddError(
"Invalid Configuration",
"min_total_memory_gb cannot be defined if the service tier is development",
)
}

if !plan.MaxTotalMemoryGb.IsNull() {
resp.Diagnostics.AddError(
"Invalid Configuration",
"min_total_memory_gb, max_total_memory_gb and num_replicas cannot be defined if the service tier is development",
"max_total_memory_gb cannot be defined if the service tier is development",
)
}

if !plan.NumReplicas.IsNull() && !plan.NumReplicas.IsUnknown() {
resp.Diagnostics.AddError(
"Invalid Configuration",
"num_replicas cannot be defined if the service tier is development",
)
}

Expand Down Expand Up @@ -506,6 +521,12 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
// behaviour as before.
maxReplicaMemoryGb = int(plan.MaxTotalMemoryGb.ValueInt64() / 3)
}
if !plan.NumReplicas.IsNull() {
numReplicas := int(plan.NumReplicas.ValueInt64())
if numReplicas > 0 {
service.NumReplicas = &numReplicas
}
}

service.MinReplicaMemoryGb = &minReplicaMemoryGb
service.MaxReplicaMemoryGb = &maxReplicaMemoryGb
Expand Down Expand Up @@ -956,6 +977,8 @@ func (r *ServiceResource) syncServiceState(ctx context.Context, state *models.Se
if service.NumReplicas != nil {
state.NumReplicas = types.Int64Value(int64(*service.NumReplicas))
}
} else {
state.NumReplicas = types.Int64Null()
}

{
Expand Down

0 comments on commit ee5b4b3

Please sign in to comment.