Skip to content

Commit 758db0f

Browse files
authored
Merge pull request #43874 from tabito-hara/f-aws_lightsail_static_ip_attachment-support_import
[Enhancement] r/aws_lightsail_static_ip_attachment: Support resource import
2 parents d6b378e + f1afd82 commit 758db0f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.changelog/43874.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_lightsail_static_ip_attachment: Support resource import
3+
```

internal/service/lightsail/static_ip_attachment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func ResourceStaticIPAttachment() *schema.Resource {
2323
ReadWithoutTimeout: resourceStaticIPAttachmentRead,
2424
DeleteWithoutTimeout: resourceStaticIPAttachmentDelete,
2525

26+
Importer: &schema.ResourceImporter{
27+
StateContext: schema.ImportStatePassthroughContext,
28+
},
29+
2630
Schema: map[string]*schema.Schema{
2731
"static_ip_name": {
2832
Type: schema.TypeString,
@@ -65,7 +69,7 @@ func resourceStaticIPAttachmentRead(ctx context.Context, d *schema.ResourceData,
6569
var diags diag.Diagnostics
6670
conn := meta.(*conns.AWSClient).LightsailClient(ctx)
6771

68-
staticIpName := d.Get("static_ip_name").(string)
72+
staticIpName := d.Id()
6973
log.Printf("[INFO] Reading Lightsail Static IP Attachment: %q", staticIpName)
7074
out, err := conn.GetStaticIp(ctx, &lightsail.GetStaticIpInput{
7175
StaticIpName: aws.String(staticIpName),
@@ -86,6 +90,7 @@ func resourceStaticIPAttachmentRead(ctx context.Context, d *schema.ResourceData,
8690

8791
d.Set("instance_name", out.StaticIp.AttachedTo)
8892
d.Set(names.AttrIPAddress, out.StaticIp.IpAddress)
93+
d.Set("static_ip_name", out.StaticIp.Name)
8994

9095
return diags
9196
}

internal/service/lightsail/static_ip_attachment_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestAccLightsailStaticIPAttachment_basic(t *testing.T) {
2626
staticIpName := fmt.Sprintf("tf-test-lightsail-%s", sdkacctest.RandString(5))
2727
instanceName := fmt.Sprintf("tf-test-lightsail-%s", sdkacctest.RandString(5))
2828
keypairName := fmt.Sprintf("tf-test-lightsail-%s", sdkacctest.RandString(5))
29+
resourceName := "aws_lightsail_static_ip_attachment.test"
2930

3031
resource.ParallelTest(t, resource.TestCase{
3132
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
@@ -36,10 +37,15 @@ func TestAccLightsailStaticIPAttachment_basic(t *testing.T) {
3637
{
3738
Config: testAccStaticIPAttachmentConfig_basic(staticIpName, instanceName, keypairName),
3839
Check: resource.ComposeAggregateTestCheckFunc(
39-
testAccCheckStaticIPAttachmentExists(ctx, "aws_lightsail_static_ip_attachment.test"),
40-
resource.TestCheckResourceAttrSet("aws_lightsail_static_ip_attachment.test", names.AttrIPAddress),
40+
testAccCheckStaticIPAttachmentExists(ctx, resourceName),
41+
resource.TestCheckResourceAttrSet(resourceName, names.AttrIPAddress),
4142
),
4243
},
44+
{
45+
ResourceName: resourceName,
46+
ImportState: true,
47+
ImportStateVerify: true,
48+
},
4349
},
4450
})
4551
}

0 commit comments

Comments
 (0)