Skip to content

Commit

Permalink
Add http_api_url as attribute reference
Browse files Browse the repository at this point in the history
  • Loading branch information
tleguijt committed Oct 26, 2020
1 parent 9e5d4f3 commit f367f52
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion serverless/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func resourceDeployment() *schema.Resource {
Optional: true,
Computed: true,
},
"http_api_url": {
Type: schema.TypeString,
Computed: true,
},
"aws_config": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -149,9 +153,12 @@ func resourceDeploymentRead(d *schema.ResourceData, m interface{}) error {

cf := cloudformation.New(sess, &aws.Config{Credentials: creds})

_, err := cf.DescribeStacks(&cloudformation.DescribeStacksInput{
stacksOutput, err := cf.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: aws.String(strings.Join([]string{id, stage}, "-")),
})

setStackInfo(stacksOutput, d)

if err != nil {
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() == "ValidationError" && strings.Contains(aerr.Message(), "does not exist") {
Expand Down
22 changes: 22 additions & 0 deletions serverless/stack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package serverless

import (
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func setStackInfo(stacksOutput *cloudformation.DescribeStacksOutput, d *schema.ResourceData) error {
if len(stacksOutput.Stacks) == 0 {
return nil
}

stack := stacksOutput.Stacks[0]

for _, output := range stack.Outputs {
if *output.OutputKey == "HttpApiUrl" {
d.Set("http_api_url", *output.OutputValue)
}
}

return nil
}

0 comments on commit f367f52

Please sign in to comment.