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

resource/aws_service_discovery_service: Add type argument #28778

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .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
```
18 changes: 14 additions & 4 deletions internal/service/servicediscovery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ func ResourceService() *schema.Resource {
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validation.StringInSlice(servicediscovery.ServiceTypeOption_Values(), false),
},
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down Expand Up @@ -171,11 +178,14 @@ 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())
}

log.Printf("[DEBUG] Creating Service Discovery Service: %s", input)
output, err := conn.CreateServiceWithContext(ctx, input)

if err != nil {
Expand All @@ -201,7 +211,7 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter
}

if err != nil {
return diag.Errorf("error reading Service Discovery Service (%s): %s", d.Id(), err)
return diag.Errorf("reading Service Discovery Service (%s): %s", d.Id(), err)
}

arn := aws.StringValue(service.Arn)
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 Expand Up @@ -298,12 +309,11 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int
conn := meta.(*conns.AWSClient).ServiceDiscoveryConn()

if d.Get("force_destroy").(bool) {
var deletionErrs *multierror.Error
input := &servicediscovery.ListInstancesInput{
ServiceId: aws.String(d.Id()),
}

var deletionErrs *multierror.Error

err := conn.ListInstancesPagesWithContext(ctx, input, func(page *servicediscovery.ListInstancesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
Expand Down
63 changes: 60 additions & 3 deletions internal/service/servicediscovery/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestAccServiceDiscoveryService_private(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "health_check_custom_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "health_check_custom_config.0.failure_threshold", "5"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "type", "DNS_HTTP"),
),
},
{
Expand All @@ -71,6 +72,7 @@ func TestAccServiceDiscoveryService_private(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "health_check_custom_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "health_check_custom_config.0.failure_threshold", "5"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "type", "DNS_HTTP"),
),
},
},
Expand Down Expand Up @@ -144,8 +146,38 @@ func TestAccServiceDiscoveryService_public(t *testing.T) {
})
}

func TestAccServiceDiscoveryService_private_http(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
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))
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_service_discovery_service.test"

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -174,7 +206,7 @@ func TestAccServiceDiscoveryService_http(t *testing.T) {
}

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

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -196,7 +228,7 @@ func TestAccServiceDiscoveryService_disappears(t *testing.T) {
}

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

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -360,6 +392,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