Skip to content

Commit

Permalink
resource/aws_service_discovery_service: Add attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewradamis-paay committed Jan 9, 2023
1 parent 685c27d commit 9302f34
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/28778.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_service_discovery_service: Add `type` argument
```
11 changes: 11 additions & 0 deletions internal/service/servicediscovery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func ResourceService() *schema.Resource {
ForceNew: true,
Computed: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
},
Expand Down Expand Up @@ -171,6 +177,10 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int
input.NamespaceId = aws.String(v.(string))
}

if v, ok := d.GetOk("type"); ok {
input.Type = aws.String(v.(string))
}

if len(tags) > 0 {
input.Tags = Tags(tags.IgnoreAWS())
}
Expand Down Expand Up @@ -230,6 +240,7 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter
}
d.Set("name", service.Name)
d.Set("namespace_id", service.NamespaceId)
d.Set("type", service.Type)

tags, err := ListTagsWithContext(ctx, conn, arn)

Expand Down
55 changes: 55 additions & 0 deletions internal/service/servicediscovery/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ func TestAccServiceDiscoveryService_public(t *testing.T) {
})
}

func TestAccServiceDiscoveryService_private_http(t *testing.T) {
rName := fmt.Sprintf("%s-%s", acctest.ResourcePrefix, sdkacctest.RandStringFromCharSet(8, sdkacctest.CharSetAlpha))
resourceName := "aws_service_discovery_service.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckPartitionHasService(servicediscovery.EndpointsID, t) },
ErrorCheck: acctest.ErrorCheck(t, servicediscovery.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceConfig_private_http(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceExists(resourceName),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "servicediscovery", regexp.MustCompile(`service/.+`)),
resource.TestCheckResourceAttrSet(resourceName, "namespace_id"),
resource.TestCheckResourceAttr(resourceName, "type", "HTTP"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}

func TestAccServiceDiscoveryService_http(t *testing.T) {
rName := fmt.Sprintf("%s-%s", acctest.ResourcePrefix, sdkacctest.RandStringFromCharSet(8, sdkacctest.CharSetAlpha))
resourceName := "aws_service_discovery_service.test"
Expand Down Expand Up @@ -360,6 +390,31 @@ resource "aws_service_discovery_service" "test" {
`, rName, th)
}

func testAccServiceConfig_private_http(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = %[1]q
}
}
resource "aws_service_discovery_private_dns_namespace" "test" {
name = "%[1]s.test"
vpc = aws_vpc.test.id
}
resource "aws_service_discovery_service" "test" {
name = %[1]q
namespace_id = aws_service_discovery_private_dns_namespace.test.id
type = "HTTP"
}
`, rName)
}

func testAccServiceConfig_public(rName string, th int, path string) string {
return fmt.Sprintf(`
resource "aws_service_discovery_public_dns_namespace" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/service_discovery_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The following arguments are supported:
* `force_destroy` - (Optional, Default:false ) A boolean that indicates all instances should be deleted from the service so that the service can be destroyed without error. These instances are not recoverable.
* `health_check_custom_config` - (Optional, ForceNew) A complex type that contains settings for ECS managed health checks.
* `namespace_id` - (Optional) The ID of the namespace that you want to use to create the service.
* `type` - (Optional) If present, specifies that the service instances are only discoverable using the `DiscoverInstances` API operation. No DNS records is registered for the service instances. The only valid value is `HTTP`.
* `tags` - (Optional) A map of tags to assign to the service. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

### dns_config
Expand Down

0 comments on commit 9302f34

Please sign in to comment.