-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6708 from ewbankkit/issue-6707
Add aws_appmesh_mesh resource
- Loading branch information
Showing
7 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appmesh" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsAppmeshMesh() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsAppmeshMeshCreate, | ||
Read: resourceAwsAppmeshMeshRead, | ||
Delete: resourceAwsAppmeshMeshDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"created_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"last_updated_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsAppmeshMeshCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).appmeshconn | ||
|
||
meshName := d.Get("name").(string) | ||
req := &appmesh.CreateMeshInput{ | ||
MeshName: aws.String(meshName), | ||
} | ||
|
||
log.Printf("[DEBUG] Creating App Mesh service mesh: %#v", req) | ||
_, err := conn.CreateMesh(req) | ||
if err != nil { | ||
return fmt.Errorf("error creating App Mesh service mesh: %s", err) | ||
} | ||
|
||
d.SetId(meshName) | ||
|
||
return resourceAwsAppmeshMeshRead(d, meta) | ||
} | ||
|
||
func resourceAwsAppmeshMeshRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).appmeshconn | ||
|
||
resp, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{ | ||
MeshName: aws.String(d.Id()), | ||
}) | ||
if err != nil { | ||
if isAWSErr(err, "NotFoundException", "") { | ||
log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
return fmt.Errorf("error reading App Mesh service mesh: %s", err) | ||
} | ||
if aws.StringValue(resp.Mesh.Status.Status) == appmesh.MeshStatusCodeDeleted { | ||
log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.Set("name", resp.Mesh.MeshName) | ||
d.Set("arn", resp.Mesh.Metadata.Arn) | ||
d.Set("created_date", resp.Mesh.Metadata.CreatedAt.Format(time.RFC3339)) | ||
d.Set("last_updated_date", resp.Mesh.Metadata.LastUpdatedAt.Format(time.RFC3339)) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsAppmeshMeshDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).appmeshconn | ||
|
||
log.Printf("[DEBUG] App Mesh service mesh: %s", d.Id()) | ||
_, err := conn.DeleteMesh(&appmesh.DeleteMeshInput{ | ||
MeshName: aws.String(d.Id()), | ||
}) | ||
if err != nil { | ||
if isAWSErr(err, "NotFoundException", "") { | ||
return nil | ||
} | ||
return fmt.Errorf("error deleting App Mesh service mesh: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appmesh" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func testAccAwsAppmeshMesh_basic(t *testing.T) { | ||
var mesh appmesh.MeshData | ||
resourceName := "aws_appmesh_mesh.foo" | ||
rName := fmt.Sprintf("tf-test-%d", acctest.RandInt()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAppmeshMeshDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAppmeshMeshConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAppmeshMeshExists( | ||
resourceName, &mesh), | ||
resource.TestCheckResourceAttr( | ||
resourceName, "name", rName), | ||
resource.TestCheckResourceAttrSet( | ||
resourceName, "created_date"), | ||
resource.TestCheckResourceAttrSet( | ||
resourceName, "last_updated_date"), | ||
resource.TestMatchResourceAttr( | ||
resourceName, "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:appmesh:[^:]+:\\d{12}:mesh/%s", rName))), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAppmeshMeshDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).appmeshconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_appmesh_mesh" { | ||
continue | ||
} | ||
|
||
_, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{ | ||
MeshName: aws.String(rs.Primary.Attributes["name"]), | ||
}) | ||
if err != nil { | ||
if isAWSErr(err, "NotFoundException", "") { | ||
return nil | ||
} | ||
return err | ||
} | ||
return fmt.Errorf("still exist.") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckAppmeshMeshExists(name string, v *appmesh.MeshData) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).appmeshconn | ||
|
||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No ID is set") | ||
} | ||
|
||
resp, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{ | ||
MeshName: aws.String(rs.Primary.Attributes["name"]), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*v = *resp.Mesh | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccAppmeshMeshConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_appmesh_mesh" "foo" { | ||
name = "%s" | ||
} | ||
`, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAccAWSAppmesh(t *testing.T) { | ||
testCases := map[string]map[string]func(t *testing.T){ | ||
"Mesh": { | ||
"basic": testAccAwsAppmeshMesh_basic, | ||
}, | ||
} | ||
|
||
for group, m := range testCases { | ||
m := m | ||
t.Run(group, func(t *testing.T) { | ||
for name, tc := range m { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_appmesh_mesh" | ||
sidebar_current: "docs-aws-resource-appmesh-mesh" | ||
description: |- | ||
Provides an AWS App Mesh service mesh resource. | ||
--- | ||
|
||
# aws_appmesh_mesh | ||
|
||
Provides an AWS App Mesh service mesh resource. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "aws_appmesh_mesh" "simple" { | ||
name = "simpleapp" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name to use for the service mesh. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The ID of the service mesh. | ||
* `arn` - The ARN of the service mesh. | ||
* `created_date` - The creation date of the service mesh. | ||
* `last_updated_date` - The last update date of the service mesh. | ||
|
||
## Import | ||
|
||
App Mesh service meshes can be imported using the `name`, e.g. | ||
|
||
``` | ||
$ terraform import aws_appmesh_mesh.simple simpleapp | ||
``` |