|
| 1 | +package aws |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/aws/aws-sdk-go/aws/endpoints" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccAWSServiceName_basic(t *testing.T) { |
| 12 | + dataSourceName := "data.aws_service_name.default" |
| 13 | + |
| 14 | + resource.ParallelTest(t, resource.TestCase{ |
| 15 | + PreCheck: func() { testAccPreCheck(t) }, |
| 16 | + Providers: testAccProviders, |
| 17 | + Steps: []resource.TestStep{ |
| 18 | + { |
| 19 | + Config: testAccCheckAwsServiceNameConfig_basic(), |
| 20 | + Check: resource.ComposeTestCheckFunc( |
| 21 | + resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), |
| 22 | + resource.TestCheckResourceAttr(dataSourceName, "service", endpoints.Ec2ServiceID), |
| 23 | + resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("%s.%s.%s", "com.amazonaws", testAccGetRegion(), endpoints.Ec2ServiceID)), |
| 24 | + resource.TestCheckResourceAttr(dataSourceName, "service_prefix", "com.amazonaws"), |
| 25 | + ), |
| 26 | + }, |
| 27 | + }, |
| 28 | + }) |
| 29 | +} |
| 30 | + |
| 31 | +func TestAccAWSServiceName_byServiceName(t *testing.T) { |
| 32 | + dataSourceName := "data.aws_service_name.test" |
| 33 | + |
| 34 | + resource.ParallelTest(t, resource.TestCase{ |
| 35 | + PreCheck: func() { testAccPreCheck(t) }, |
| 36 | + Providers: testAccProviders, |
| 37 | + Steps: []resource.TestStep{ |
| 38 | + { |
| 39 | + Config: testAccCheckAwsServiceNameConfig_byServiceName(), |
| 40 | + Check: resource.ComposeTestCheckFunc( |
| 41 | + resource.TestCheckResourceAttr(dataSourceName, "region", endpoints.ApNortheast1RegionID), |
| 42 | + resource.TestCheckResourceAttr(dataSourceName, "service", endpoints.S3ServiceID), |
| 43 | + resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("%s.%s.%s", "cn.com.amazonaws", endpoints.ApNortheast1RegionID, endpoints.S3ServiceID)), |
| 44 | + resource.TestCheckResourceAttr(dataSourceName, "service_prefix", "cn.com.amazonaws"), |
| 45 | + ), |
| 46 | + }, |
| 47 | + }, |
| 48 | + }) |
| 49 | +} |
| 50 | + |
| 51 | +func TestAccAWSServiceName_byPart(t *testing.T) { |
| 52 | + dataSourceName := "data.aws_service_name.test" |
| 53 | + |
| 54 | + resource.ParallelTest(t, resource.TestCase{ |
| 55 | + PreCheck: func() { testAccPreCheck(t) }, |
| 56 | + Providers: testAccProviders, |
| 57 | + Steps: []resource.TestStep{ |
| 58 | + { |
| 59 | + Config: testAccCheckAwsServiceNameConfig_byPart(), |
| 60 | + Check: resource.ComposeTestCheckFunc( |
| 61 | + resource.TestCheckResourceAttr(dataSourceName, "region", testAccGetRegion()), |
| 62 | + resource.TestCheckResourceAttr(dataSourceName, "service", endpoints.Ec2ServiceID), |
| 63 | + resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("%s.%s.%s", "com.amazonaws", testAccGetRegion(), endpoints.Ec2ServiceID)), |
| 64 | + resource.TestCheckResourceAttr(dataSourceName, "service_prefix", "com.amazonaws"), |
| 65 | + ), |
| 66 | + }, |
| 67 | + }, |
| 68 | + }) |
| 69 | +} |
| 70 | + |
| 71 | +func testAccCheckAwsServiceNameConfig_basic() string { |
| 72 | + return fmt.Sprintf(` |
| 73 | +data "aws_service_name" "default" {} |
| 74 | +`) |
| 75 | +} |
| 76 | + |
| 77 | +func testAccCheckAwsServiceNameConfig_byServiceName() string { |
| 78 | + // lintignore:AWSAT003 |
| 79 | + return fmt.Sprintf(` |
| 80 | +data "aws_service_name" "test" { |
| 81 | + name = "cn.com.amazonaws.ap-northeast-1.s3" |
| 82 | +} |
| 83 | +`) |
| 84 | +} |
| 85 | + |
| 86 | +func testAccCheckAwsServiceNameConfig_byPart() string { |
| 87 | + return fmt.Sprintf(` |
| 88 | +data "aws_region" "current" {} |
| 89 | +
|
| 90 | +data "aws_service_name" "test" { |
| 91 | + service = "ec2" |
| 92 | + region = data.aws_region.current.name |
| 93 | + service_prefix = "com.amazonaws" |
| 94 | +} |
| 95 | +`) |
| 96 | +} |
0 commit comments