diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000000..4a839f76e8e3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +# This GitHub action can publish assets for release when a tag is created. +# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). +# +# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your +# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` +# secret. If you would rather own your own GPG handling, please fork this action +# or use an alternative one for key handling. +# +# You will need to pass the `--batch` flag to `gpg` in your signing step +# in `goreleaser` to indicate this is being used in a non-interactive mode. +# +name: release +on: + push: + tags: + - "v*" +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + - name: Import GPG key + id: import_gpg + uses: paultyng/ghaction-import-gpg@v2.1.0 + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + PASSPHRASE: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 8d1a78155dd9..42b279a4b72b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,43 +1,39 @@ -archives: - - files: - - none* - format: zip - name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' +# Visit https://goreleaser.com for documentation on how to customize this +# behavior. before: hooks: - - go mod download + # this is just an example and not a requirement for provider building/publishing + - go mod tidy builds: - - binary: '{{ .ProjectName }}_{{ .Version }}' + - env: + # goreleaser does not work with CGO, it could also complicate + # usage by users in CI/CD systems like Terraform Cloud where + # they are unable to install libraries. + - CGO_ENABLED=0 + mod_timestamp: "{{ .CommitTimestamp }}" flags: - -trimpath + ldflags: + - "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}" + goos: + - linux + - darwin goarch: - - '386' - amd64 - arm - arm64 - goos: - - darwin - - freebsd - - linux - - windows - ignore: - - goarch: '386' - goos: darwin - ldflags: - - -s -w -X aws/version.ProviderVersion={{.Version}} - mod_timestamp: '{{ .CommitTimestamp }}' -changelog: - skip: true + binary: "{{ .ProjectName }}_v{{ .Version }}" +archives: + - format: zip + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" checksum: - name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" algorithm: sha256 -env: - - CGO_ENABLED=0 -release: - disable: true signs: - artifacts: checksum args: + # if you are using this is a GitHub action or some other automated pipeline, you + # need to pass the batch flag to indicate its not interactive. - "--batch" - "--local-user" - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key @@ -45,3 +41,8 @@ signs: - "${signature}" - "--detach-sign" - "${artifact}" +release: + # If you want to manually examine the release before its live, uncomment this line: + # draft: true +changelog: + skip: true diff --git a/aws/resource_aws_appsync_datasource.go b/aws/resource_aws_appsync_datasource.go index da693a564df8..1f69cfb70f91 100644 --- a/aws/resource_aws_appsync_datasource.go +++ b/aws/resource_aws_appsync_datasource.go @@ -108,6 +108,42 @@ func resourceAwsAppsyncDatasource() *schema.Resource { Type: schema.TypeString, Required: true, }, + "authorization_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "authorization_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + appsync.AuthorizationTypeAwsIam, + }, true), + StateFunc: func(v interface{}) string { + return strings.ToUpper(v.(string)) + }, + }, + "aws_iam_config": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "signing_region": { + Type: schema.TypeString, + Optional: true, + }, + "signing_service_name": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, }, }, ConflictsWith: []string{"dynamodb_config", "elasticsearch_config", "lambda_config"}, @@ -385,6 +421,36 @@ func flattenAppsyncElasticsearchDataSourceConfig(config *appsync.ElasticsearchDa return []map[string]interface{}{result} } +func expandAppsyncAwsIamConfig(l []interface{}) *appsync.AwsIamConfig { + if len(l) == 0 { + return nil + } + + configured := l[0].(map[string]interface{}) + + result := &appsync.AwsIamConfig{ + SigningRegion: aws.String(configured["signing_region"].(string)), + SigningServiceName: aws.String(configured["signing_service_name"].(string)), + } + + return result +} + +func expandAppsyncHTTPAuthorizationConfig(l []interface{}) *appsync.AuthorizationConfig { + if len(l) == 0 { + return nil + } + + configured := l[0].(map[string]interface{}) + + result := &appsync.AuthorizationConfig{ + AuthorizationType: aws.String(configured["authorization_type"].(string)), + AwsIamConfig: expandAppsyncAwsIamConfig(configured["aws_iam_config"].([]interface{})), + } + + return result +} + func expandAppsyncHTTPDataSourceConfig(l []interface{}) *appsync.HttpDataSourceConfig { if len(l) == 0 || l[0] == nil { return nil @@ -393,19 +459,47 @@ func expandAppsyncHTTPDataSourceConfig(l []interface{}) *appsync.HttpDataSourceC configured := l[0].(map[string]interface{}) result := &appsync.HttpDataSourceConfig{ - Endpoint: aws.String(configured["endpoint"].(string)), + Endpoint: aws.String(configured["endpoint"].(string)), + AuthorizationConfig: expandAppsyncHTTPAuthorizationConfig(configured["authorization_config"].([]interface{})), } return result } +func flattenAppsyncAwsIamConfig(config *appsync.AwsIamConfig) []map[string]interface{} { + if config == nil { + return nil + } + + result := map[string]interface{}{ + "signing_region": aws.StringValue(config.SigningRegion), + "signing_service_name": aws.StringValue(config.SigningServiceName), + } + + return []map[string]interface{}{result} +} + +func flattenAppsyncHTTPAuthorizationConfig(config *appsync.AuthorizationConfig) []map[string]interface{} { + if config == nil { + return nil + } + + result := map[string]interface{}{ + "authorization_type": aws.StringValue(config.AuthorizationType), + "aws_iam_config": flattenAppsyncAwsIamConfig(config.AwsIamConfig), + } + + return []map[string]interface{}{result} +} + func flattenAppsyncHTTPDataSourceConfig(config *appsync.HttpDataSourceConfig) []map[string]interface{} { if config == nil { return nil } result := map[string]interface{}{ - "endpoint": aws.StringValue(config.Endpoint), + "endpoint": aws.StringValue(config.Endpoint), + "authorization_config": flattenAppsyncHTTPAuthorizationConfig(config.AuthorizationConfig), } return []map[string]interface{}{result} diff --git a/aws/resource_aws_appsync_datasource_test.go b/aws/resource_aws_appsync_datasource_test.go index a10eb4f6663e..0af01dd1791b 100644 --- a/aws/resource_aws_appsync_datasource_test.go +++ b/aws/resource_aws_appsync_datasource_test.go @@ -178,6 +178,37 @@ func TestAccAwsAppsyncDatasource_ElasticsearchConfig_Region(t *testing.T) { }) } +func TestAccAwsAppsyncDatasource_HTTPConfig_AuthorizationConfig(t *testing.T) { + rName := fmt.Sprintf("tfacctest%d", acctest.RandInt()) + resourceName := "aws_appsync_datasource.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(appsync.EndpointsID, t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsAppsyncDatasourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAppsyncDatasourceConfig_HTTPConfig_AuthorizationConfig(rName, testAccGetRegion(), "s3"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsAppsyncDatasourceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "http_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "http_config.0.authorization_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "http_config.0.authorization_config.0.authorization_type", "AWS_IAM"), + resource.TestCheckResourceAttr(resourceName, "http_config.0.authorization_config.0.aws_iam_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "http_config.0.authorization_config.0.aws_iam_config.0.signing_region", testAccGetRegion()), + resource.TestCheckResourceAttr(resourceName, "http_config.0.authorization_config.0.aws_iam_config.0.signing_service_name", "s3"), + resource.TestCheckResourceAttr(resourceName, "type", "HTTP"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAwsAppsyncDatasource_HTTPConfig_Endpoint(t *testing.T) { rName := fmt.Sprintf("tfacctest%d", acctest.RandInt()) resourceName := "aws_appsync_datasource.test" @@ -705,6 +736,52 @@ resource "aws_appsync_datasource" "test" { `, rName, rName, region) } +func testAccAppsyncDatasourceConfig_HTTPConfig_AuthorizationConfig(rName, region string, serviceName string) string { + return fmt.Sprintf(` +resource "aws_iam_role" "test" { + name = %q + + assume_role_policy = <