Skip to content

Commit

Permalink
Merge pull request #133 from klothoplatform/skip_pulumi_internal
Browse files Browse the repository at this point in the history
Fix stage properties to have both InvokeURL and Endpoint
  • Loading branch information
gordon-klotho authored Aug 14, 2024
2 parents 0de81c7 + b44b756 commit ad31162
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/testdata/cf_distribution.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resources:
- TLSv1
- SSLv3
- TLSv1.1
DomainName: aws:api_stage:rest_api_1:cloudfront_distribution_2-rest_api_1#StageInvokeUrl
DomainName: aws:api_stage:rest_api_1:cloudfront_distribution_2-rest_api_1#DomainName
OriginId: cloudfront_distribution_2-rest_api_1
OriginPath: /stage
- DomainName: aws:s3_bucket:s3-bucket-3#BucketRegionalDomainName
Expand Down
3 changes: 2 additions & 1 deletion pkg/infra/iac/templates/aws/api_stage/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function create(args: Args): aws.apigateway.Stage {

function properties(object: ReturnType<typeof create>, args: Args) {
return {
StageInvokeUrl: object.invokeUrl.apply((d) => d.split('//')[1].split('/')[0]),
InvokeUrl: object.invokeUrl,
DomainName: object.invokeUrl.apply((d) => d.split('//')[1].split('/')[0]),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ iac_qualified_type: aws:lb/loadBalancer:LoadBalancer
property_mappings:
arn: Arn
id: Id
loadBalancerType: Type
2 changes: 1 addition & 1 deletion pkg/k2/constructs/templates/aws/api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ resources:
outputs:
Endpoint:
description: The endpoint for the API
value: ${resources:APIStage#StageInvokeUrl}
value: ${resources:APIStage#InvokeUrl}
7 changes: 7 additions & 0 deletions pkg/k2/stack/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/klothoplatform/klotho/pkg/construct"
Expand Down Expand Up @@ -66,6 +67,12 @@ func GetState(ctx context.Context, stack StackInterface) (State, error) {

resourcesByResourceId := make(map[construct.ResourceId]apitype.ResourceV3)
for _, res := range unmarshalledState.Resources {
resType := res.URN.QualifiedType()
switch {
case strings.HasPrefix(string(resType), "pulumi:"), strings.HasPrefix(string(resType), "docker:"):
// Skip known non-cloud / Pulumi internal resource (eg: Stack or Provider)
continue
}
id, ok := resourceIdByUrn[string(res.URN)]
if !ok {
zap.S().Warnf("could not find resource id for urn %s", res.URN)
Expand Down
4 changes: 2 additions & 2 deletions pkg/k2/testdata/bucket_ro/my-bucket.resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ resources:
RESOURCE_NAME: my-bucket
edges:
outputs:
Bucket:
ref: aws:s3_bucket:my-bucket#Bucket
BucketArn:
ref: aws:s3_bucket:my-bucket#Arn
BucketRegionalDomainName:
ref: aws:s3_bucket:my-bucket#BucketRegionalDomainName
Bucket:
ref: aws:s3_bucket:my-bucket#Bucket
2 changes: 1 addition & 1 deletion pkg/k2/testdata/function/my-api.engine_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constraints:
data: {}
- scope: output
operator: must_exist
ref: aws:api_stage:my-api-api:my-api-stage#StageInvokeUrl
ref: aws:api_stage:my-api-api:my-api-stage#InvokeUrl
name: Endpoint
value: null
resources:
Expand Down
2 changes: 1 addition & 1 deletion pkg/k2/testdata/function/my-api.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const my_api_stage = new aws.apigateway.Stage("my-api-stage", {
export const my_api_stage_Url = my_api_stage.invokeUrl

export const $outputs = {
Endpoint: my_api_stage.invokeUrl.apply((d) => d.split('//')[1].split('/')[0]),
Endpoint: my_api_stage.invokeUrl,
}

export const $urns = {
Expand Down
2 changes: 1 addition & 1 deletion pkg/k2/testdata/function/my-api.resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ edges:
aws:lambda_permission:docker-func-docker-func-function -> aws:lambda_function:docker-func-function:
outputs:
Endpoint:
ref: aws:api_stage:my-api-api:my-api-stage#StageInvokeUrl
ref: aws:api_stage:my-api-api:my-api-stage#InvokeUrl
2 changes: 1 addition & 1 deletion pkg/k2/testdata/simple_api/my-api.engine_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constraints:
data: {}
- scope: output
operator: must_exist
ref: aws:api_stage:my-api-api:my-api-stage#StageInvokeUrl
ref: aws:api_stage:my-api-api:my-api-stage#InvokeUrl
name: Endpoint
value: null
resources:
Expand Down
2 changes: 1 addition & 1 deletion pkg/k2/testdata/simple_api/my-api.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const my_api_stage = new aws.apigateway.Stage("my-api-stage", {
export const my_api_stage_Url = my_api_stage.invokeUrl

export const $outputs = {
Endpoint: my_api_stage.invokeUrl.apply((d) => d.split('//')[1].split('/')[0]),
Endpoint: my_api_stage.invokeUrl,
}

export const $urns = {
Expand Down
2 changes: 1 addition & 1 deletion pkg/k2/testdata/simple_api/my-api.resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@ edges:
aws:security_group:default-network-vpc:my-container-service-security_group -> aws:vpc:default-network-vpc:
outputs:
Endpoint:
ref: aws:api_stage:my-api-api:my-api-stage#StageInvokeUrl
ref: aws:api_stage:my-api-api:my-api-stage#InvokeUrl
2 changes: 1 addition & 1 deletion pkg/knowledgebase/properties/resource_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *ResourceProperty) Validate(resource *construct.Resource, value any, ctx
if !ok {
return fmt.Errorf("invalid resource value %v", value)
}
if r.AllowedTypes != nil && len(r.AllowedTypes) > 0 && !r.AllowedTypes.MatchesAny(id) {
if len(r.AllowedTypes) > 0 && !r.AllowedTypes.MatchesAny(id) {
return fmt.Errorf("resource value %v does not match allowed types %s", value, r.AllowedTypes)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/knowledgebase/properties/string_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *StringProperty) Validate(resource *construct.Resource, value any, ctx k
}
}

if s.AllowedValues != nil && len(s.AllowedValues) > 0 && !collectionutil.Contains(s.AllowedValues, stringVal) {
if len(s.AllowedValues) > 0 && !collectionutil.Contains(s.AllowedValues, stringVal) {
return fmt.Errorf("value %s is not allowed. allowed values are %s", stringVal, s.AllowedValues)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ operational_rules:
- TLSv1
- SSLv3
- TLSv1.1
DomainName: '{{ .Target }}#StageInvokeUrl'
DomainName: '{{ .Target }}#DomainName'
OriginId: '{{ .Target.Name }}'
OriginPath: '/{{ fieldValue "StageName" .Target }}'
- resource: '{{ .Source }}'
configuration:
field: CacheBehaviors
value: |
[
{{ $targetOriginId := .Target.Name }}
{{ $routes := makeSlice }}
{{ $integrations := allDownstream "aws:api_integration" .Target }}
Expand Down
12 changes: 8 additions & 4 deletions pkg/templates/aws/resources/api_stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ properties:
- aws:api_deployment
aws:tags:
type: model
StageInvokeUrl:
InvokeUrl:
type: string
configuration_disabled: true
deploy_time: true
DomainName:
type: string
configuration_disabled: true
deploy_time: true
Expand All @@ -39,6 +43,6 @@ views:
dataflow: small

deployment_permissions:
deploy: ["apigateway:CreateStage"]
tear_down: ["apigateway:DeleteStage"]
update: ["apigateway:UpdateStage"]
deploy: ['apigateway:CreateStage']
tear_down: ['apigateway:DeleteStage']
update: ['apigateway:UpdateStage']
2 changes: 1 addition & 1 deletion pkg/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ type boxLine struct {
// ├ 29.3s DBG > AddEdge ...
// ├ ...
// ├ Outputs
// └ └ Endpoint: <aws:api_stage:my-api-api:my-api-stage#StageInvokeUrl>
// └ └ Endpoint: <aws:api_stage:my-api-api:my-api-stage#InvokeUrl>
//
// Long lines are wrapped to fit the console width:
//
Expand Down

0 comments on commit ad31162

Please sign in to comment.