1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

確認くんはもう使わない。GIP取得はAWS公式が一番

1
Last updated at Posted at 2025-11-21

本記事の目的

GIPを取得するときに、「確認くん」はちょっと信頼できない。
本ページは信頼できるサイトを紹介します。

結論

GIP取得のお勧めのサイトは、AWSが提供しているGIP URL(参考:AWS CLI の Amazon EC2 セキュリティグループの作成、設定、および削除

https://checkip.amazonaws.com/
curl https://checkip.amazonaws.com/
xx8.xx.x4.7

とIPしか返ってこないので、CLIと親和性が高いのがとても良い。

想定利用シーン

自宅でAWSで触るとGIPの変更になやまされる方が多いと思います。

TefformでAWS環境の構築学習や試す際にコスト削減のためにApply/Destroyを繰り返すのですが、
毎回GIPを調べて変数にいれて・・・
というのがツライですよね。

そんな時は、下記のように自宅のGIPをリソース作成時に自動取得が便利です。

data "http" "myip" {
  url = "https://checkip.amazonaws.com/"
}

locals {
  home_ip = "${trimspace(data.http.myip.response_body)}/32"
}

resource "aws_security_group" "example" {
  name        = "example-sg"
  description = "Allow access from my home IP"

  ingress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = [local.home_ip]
  }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?