Skip to content

Commit

Permalink
feat: add region and service to AWS destination auth (#116)
Browse files Browse the repository at this point in the history
* wip: add region and service to AWS destination auth

* fix: open API spec from source controls should be used over live version

* chore: go generate
  • Loading branch information
leggetter authored Oct 22, 2024
1 parent eb8a85d commit 6063197
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/destination.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Whether the API key should be sent as a header or a query parameter
Read-Only:

- `access_key_id` (String, Sensitive) AWS access key id
- `region` (String) AWS region
- `secret_access_key` (String, Sensitive) AWS secret access key
- `service` (String) AWS service


<a id="nestedatt--auth_method--basic_auth"></a>
Expand Down
5 changes: 5 additions & 0 deletions docs/resources/destination.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ Required:
- `access_key_id` (String, Sensitive) AWS access key id
- `secret_access_key` (String, Sensitive) AWS secret access key

Optional:

- `region` (String) AWS region
- `service` (String) AWS service


<a id="nestedatt--auth_method--basic_auth"></a>
### Nested Schema for `auth_method.basic_auth`
Expand Down
16 changes: 15 additions & 1 deletion examples/full/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ variable "HEADER_FILTER_VALUES" {
terraform {
required_providers {
hookdeck = {
source = "hookdeck/hookdeck"
source = "hookdeck/hookdeck"
version = "0.5.0-beta.1"
}
}
}
Expand Down Expand Up @@ -65,6 +66,19 @@ resource "hookdeck_destination" "second_destination" {
}
}

resource "hookdeck_destination" "aws_destination" {
name = "aws_destination"
url = "https://mock.hookdeck.com"
auth_method = {
aws_signature = {
access_key_id = "some-access"
secret_access_key = "some-secret"
region = "us-west-2"
service = "lambda"
}
}
}

resource "hookdeck_connection" "first_connection" {
source_id = hookdeck_source.first_source.id
destination_id = hookdeck_destination.first_destination.id
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

const hookdeckOpenAPISchemaURI = "https://api.hookdeck.com/latest/openapi"
const hookdeckOpenAPISchemaURI = "https://raw.githubusercontent.com/hookdeck/hookdeck-api-schema/refs/heads/main/openapi.json"

func RunCodeGen() error {
fmt.Println("generating Hookdeck source verifications")
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/destination/authentication_awssignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
type awsSignatureAuthenticationMethodModel struct {
AccessKeyID types.String `tfsdk:"access_key_id"`
SecretAccessKey types.String `tfsdk:"secret_access_key"`
Region types.String `tfsdk:"region"`
Service types.String `tfsdk:"service"`
}

type awsSignatureAuthenticationMethod struct {
Expand All @@ -33,6 +35,16 @@ func (*awsSignatureAuthenticationMethod) schema() schema.Attribute {
Sensitive: true,
Description: `AWS secret access key`,
},
"region": schema.StringAttribute{
Optional: true,
Sensitive: false,
Description: `AWS region`,
},
"service": schema.StringAttribute{
Optional: true,
Sensitive: false,
Description: `AWS service`,
},
},
Description: `AWS Signature`,
}
Expand All @@ -42,6 +54,8 @@ func awsSignatureAuthenticationMethodAttrTypesMap() map[string]attr.Type {
return map[string]attr.Type{
"access_key_id": types.StringType,
"secret_access_key": types.StringType,
"region": types.StringType,
"service": types.StringType,
}
}

Expand All @@ -61,6 +75,12 @@ func (awsSignatureAuthenticationMethod) refresh(m *destinationResourceModel, des
m.AuthMethod.AWSSignature = &awsSignatureAuthenticationMethodModel{}
m.AuthMethod.AWSSignature.AccessKeyID = types.StringValue(destination.AuthMethod.AwsSignature.Config.AccessKeyId)
m.AuthMethod.AWSSignature.SecretAccessKey = types.StringValue(destination.AuthMethod.AwsSignature.Config.SecretAccessKey)
if destination.AuthMethod.AwsSignature.Config.Region != nil {
m.AuthMethod.AWSSignature.Region = types.StringValue(*destination.AuthMethod.AwsSignature.Config.Region)
}
if destination.AuthMethod.AwsSignature.Config.Service != nil {
m.AuthMethod.AWSSignature.Service = types.StringValue(*destination.AuthMethod.AwsSignature.Config.Service)
}
}

func (awsSignatureAuthenticationMethod) toPayload(method *destinationAuthMethodConfig) *hookdeck.DestinationAuthMethodConfig {
Expand All @@ -72,6 +92,8 @@ func (awsSignatureAuthenticationMethod) toPayload(method *destinationAuthMethodC
Config: &hookdeck.DestinationAuthMethodAwsSignatureConfig{
AccessKeyId: method.AWSSignature.AccessKeyID.ValueString(),
SecretAccessKey: method.AWSSignature.SecretAccessKey.ValueString(),
Region: method.AWSSignature.Region.ValueStringPointer(),
Service: method.AWSSignature.Service.ValueStringPointer(),
},
})
}
Expand Down

0 comments on commit 6063197

Please sign in to comment.