Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AWS AppConfig support #79

Merged
merged 25 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6a4208f
Added appconfig service, application, and config profile
Isaiah-Turner Mar 1, 2021
3c765d7
Added tag support for AppConfig
Isaiah-Turner Mar 3, 2021
6fd923b
Updated testing framework
Isaiah-Turner Mar 3, 2021
2317ca7
Fixed application acceptance tests
Isaiah-Turner Mar 3, 2021
fe80b38
Updated to ecs task set to sdk v2
Isaiah-Turner Mar 3, 2021
8089160
Added configuration profile functionality and tests
Isaiah-Turner Mar 3, 2021
cc64f48
Added initial settings pull from Appconfig
Isaiah-Turner Mar 3, 2021
3a8913a
Fixed functionality and improved test cases
Isaiah-Turner Mar 4, 2021
a0eb3d3
Added deployment stragegy resource and tests
Isaiah-Turner Mar 6, 2021
027f6aa
Added validator count check to tests
Isaiah-Turner Mar 8, 2021
2b76f5c
Added appconfig environment and tests
Isaiah-Turner Mar 8, 2021
501adda
Added deployment and tests
Isaiah-Turner Mar 8, 2021
9799992
Added hosted configuration version and tests
Isaiah-Turner Mar 9, 2021
e435395
Added hosted configuration version resource and tests
Isaiah-Turner Mar 9, 2021
e6d1d9c
Fixed extra parentheses
Isaiah-Turner Mar 9, 2021
e2a2168
Fixed deployment state and failing tests
Isaiah-Turner Mar 9, 2021
ee30db3
Fixed broken tests and changed tests to run in parallel
Isaiah-Turner Mar 9, 2021
f7edb12
Removed extra characters
Isaiah-Turner Mar 9, 2021
b04721b
Fixed update method and spelling
Isaiah-Turner Mar 15, 2021
6b64479
Formatted all terraform blocks
Isaiah-Turner Mar 15, 2021
55ee9c8
Fixed formatting for acceptance tests
Isaiah-Turner Mar 16, 2021
cae2441
improved tf formatting
Isaiah-Turner Mar 16, 2021
283d759
improved web documentation formatting
Isaiah-Turner Mar 16, 2021
83a44d6
Added documentation for new resources
Isaiah-Turner Mar 16, 2021
c402062
Fixed shortened name
Isaiah-Turner Mar 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/aws/aws-sdk-go/service/apigatewayv2"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/aws/aws-sdk-go/service/applicationautoscaling"
"github.com/aws/aws-sdk-go/service/applicationinsights"
"github.com/aws/aws-sdk-go/service/appmesh"
Expand Down Expand Up @@ -212,6 +213,7 @@ type AWSClient struct {
amplifyconn *amplify.Amplify
apigatewayconn *apigateway.APIGateway
apigatewayv2conn *apigatewayv2.ApiGatewayV2
appconfigconn *appconfig.AppConfig
appautoscalingconn *applicationautoscaling.ApplicationAutoScaling
applicationinsightsconn *applicationinsights.ApplicationInsights
appmeshconn *appmesh.AppMesh
Expand Down Expand Up @@ -454,6 +456,7 @@ func (c *Config) Client() (interface{}, error) {
apigatewayconn: apigateway.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["apigateway"])})),
apigatewayv2conn: apigatewayv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["apigateway"])})),
appautoscalingconn: applicationautoscaling.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["applicationautoscaling"])})),
appconfigconn: appconfig.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appconfig"])})),
applicationinsightsconn: applicationinsights.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["applicationinsights"])})),
appmeshconn: appmesh.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appmesh"])})),
appstreamconn: appstream.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["appstream"])})),
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var serviceNames = []string{
"acmpca",
"amplify",
"apigatewayv2",
"appconfig",
"appmesh",
"appstream",
"appsync",
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/servicetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var mapServiceNames = []string{
"amplify",
"apigateway",
"apigatewayv2",
"appconfig",
"appstream",
"appsync",
"backup",
Expand Down
1 change: 1 addition & 0 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var serviceNames = []string{
"amplify",
"apigateway",
"apigatewayv2",
"appconfig",
"appmesh",
"appstream",
"appsync",
Expand Down
18 changes: 18 additions & 0 deletions aws/internal/keyvaluetags/list_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/amplify"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/aws/aws-sdk-go/service/apigatewayv2"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/aws/aws-sdk-go/service/appsync"
Expand Down Expand Up @@ -140,6 +141,8 @@ func ServiceClientType(serviceName string) string {
funcType = reflect.TypeOf(apigateway.New)
case "apigatewayv2":
funcType = reflect.TypeOf(apigatewayv2.New)
case "appconfig":
funcType = reflect.TypeOf(appconfig.New)
case "appmesh":
funcType = reflect.TypeOf(appmesh.New)
case "appstream":
Expand Down
10 changes: 10 additions & 0 deletions aws/internal/keyvaluetags/service_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions aws/internal/keyvaluetags/update_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ func Provider() *schema.Provider {
"aws_appautoscaling_target": resourceAwsAppautoscalingTarget(),
"aws_appautoscaling_policy": resourceAwsAppautoscalingPolicy(),
"aws_appautoscaling_scheduled_action": resourceAwsAppautoscalingScheduledAction(),
"aws_appconfig_application": resourceAwsAppconfigApplication(),
"aws_appconfig_configuration_profile": resourceAwsAppconfigConfigurationProfile(),
"aws_appconfig_deployment": resourceAwsAppconfigDeployment(),
"aws_appconfig_deployment_strategy": resourceAwsAppconfigDeploymentStrategy(),
"aws_appconfig_environment": resourceAwsAppconfigEnvironment(),
"aws_appconfig_hosted_configuration_version": resourceAwsAppconfigHostedConfigurationVersion(),
"aws_appmesh_gateway_route": resourceAwsAppmeshGatewayRoute(),
"aws_appmesh_mesh": resourceAwsAppmeshMesh(),
"aws_appmesh_route": resourceAwsAppmeshRoute(),
Expand Down Expand Up @@ -1154,6 +1160,7 @@ func init() {
"acmpca",
"amplify",
"apigateway",
"appconfig",
"applicationautoscaling",
"applicationinsights",
"appmesh",
Expand Down
169 changes: 169 additions & 0 deletions aws/resource_aws_appconfig_application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsAppconfigApplication() *schema.Resource {
return &schema.Resource{
Create: resourceAwsAppconfigApplicationCreate,
Read: resourceAwsAppconfigApplicationRead,
Update: resourceAwsAppconfigApplicationUpdate,
Delete: resourceAwsAppconfigApplicationDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 64),
lizhifan marked this conversation as resolved.
Show resolved Hide resolved
),
},
"description": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.All(
validation.StringLenBetween(0, 1024),
),
},
"tags": tagsSchema(),
"id": {
Type: schema.TypeString,
lizhifan marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceAwsAppconfigApplicationCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appconfigconn
applicationName := d.Get("name").(string)
applicationDescription := d.Get("description").(string)

input := &appconfig.CreateApplicationInput{
Name: aws.String(applicationName),
Description: aws.String(applicationDescription),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().AppconfigTags(),
}

app, err := conn.CreateApplication(input)
if err != nil {
return fmt.Errorf("Error creating AppConfig application: %s", err)
}

d.SetId(aws.StringValue(app.Id))
lizhifan marked this conversation as resolved.
Show resolved Hide resolved

return resourceAwsAppconfigApplicationRead(d, meta)
}

func resourceAwsAppconfigApplicationRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appconfigconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &appconfig.GetApplicationInput{
ApplicationId: aws.String(d.Id()),
}

output, err := conn.GetApplication(input)

if isAWSErr(err, appconfig.ErrCodeResourceNotFoundException, "") {
log.Printf("[WARN] Appconfig Application (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

if err != nil {
return fmt.Errorf("error getting AppConfig Application (%s): %s", d.Id(), err)
}

if output == nil {
return fmt.Errorf("error getting AppConfig Application (%s): empty response", d.Id())
}

appARN := arn.ARN{
AccountID: meta.(*AWSClient).accountid,
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Resource: fmt.Sprintf("application/%s", aws.StringValue(output.Id)),
Service: "appconfig",
}.String()

d.Set("arn", appARN)
d.Set("name", output.Name)
d.Set("description", output.Description)

tags, err := keyvaluetags.AppconfigListTags(conn, appARN)
if err != nil {
return fmt.Errorf("error getting tags for AppConfig Application (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
}

func resourceAwsAppconfigApplicationUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appconfigconn

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if err := keyvaluetags.AppconfigUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating AppConfig (%s) tags: %s", d.Id(), err)
}
}

if d.HasChanges("description", "name") {
appDesc := d.Get("description").(string)
appName := d.Get("name").(string)

updateInput := &appconfig.UpdateApplicationInput{
ApplicationId: aws.String(d.Id()),
Description: aws.String(appDesc),
Name: aws.String(appName),
}

_, err := conn.UpdateApplication(updateInput)
if err != nil {
return fmt.Errorf("error updating AppConfig Application(%s): %s", d.Id(), err)
}
}

return resourceAwsAppconfigApplicationRead(d, meta)
}

func resourceAwsAppconfigApplicationDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appconfigconn

input := &appconfig.DeleteApplicationInput{
ApplicationId: aws.String(d.Id()),
}

_, err := conn.DeleteApplication(input)

if isAWSErr(err, appconfig.ErrCodeResourceNotFoundException, "") {
return nil
}

if err != nil {
return fmt.Errorf("error deleting Appconfig Application (%s): %s", d.Id(), err)
}

return nil
}
Loading